How to Keep both debug and release App in Android with Single Line of Code

when we are developing application we use debug mode. But If we need to publish app we need to do some changes and also we have to disable debugging. But the issue is if we need to keep both dedug and release app in phone????

With the default configuration in Gradle we cannot keep both debug and release app in same time. The reason for that is the application id is same. Therefore if we can change the application id for debug mode slightly we can keep both apps.

First we need to add this code line to the gradle under the debug config

debug {
applicationIdSuffix ".debug"
}

You can change this debug to anything you want. What id does is it append this suffix to your appId when generate.

So that’s it . Now you can keep both debug and release app.

Firebase

If you are using firebase in your app you have to do some work to make this work. But not much , we need to change the google-services.json file content to work with new applicationId. Follow below steps.

1.First log in to firebase and select your app.

2.In the top left corner there is Project overview Section. Click the cog wheel icon in there and select “Project settings”

3. After it open the project setting page select the “General” tab. Then scroll down and it show the “Your Apps” section. In there we need to add new App. Click “Add App”  button.

4. Then select Android from popup.

5. Then add new package name. In there we need to add the package name with end of “.debug” . If you used different applicationIdSuffix in gradle use that name here.

6. Click Register and download new json.

7. Replace your current Json with new json.

8. Build and Run. All will work like charm

Leave a Reply