how to manage debug and release version on android device?
Asked Answered
C

6

27

I'm new to Android dev and I'm almost ready to release a first version of my app :)

While testing the signed release apk on my phone, it refuse to install because the debug version is installed with the debug signature.

So I have to uninstall the debug version but it delete all my database (and it will do it to my friends who are testing it).

Is there a way to manage a debug and a release version of the same app without losing data?

Cochleate answered 10/2, 2011 at 17:2 Comment(1)
I'd be very interested in a solution for this too. However, I'm fairly certain that short of changing the package names, this won't be possible. :/Weeny
D
4

I'm not aware of any easy way to do get around the uninstall/reinstall process, so your options include...

  • Buy a second device for testing (some Android devices are very cheap now, especially on eBay)
  • Use the emulator for testing

I see the same issue, but it's to be expected, so I use the phone for debug dev, and the tablet for production testing. When I'm close to a release, I test the production version on both devices and the emulator.

With your testers, I'd advise that you always give them release versions, but you could include extensive logging to help with problems. Debug versions are then only used by you, and release versions by them. If you provide testers with a release version, they use, and accumulate data, when they come to upgrade to the next version, the data can be retained (or updated, if you change the schema) to migrate their data.

I don't see a need for your testers to be using debug & release versions.

Disapprove answered 10/2, 2011 at 17:23 Comment(3)
it's because I provide a debug menu with some advanced actions only available when the app is signed wish debug signatureCochleate
In that case I would suggest you add a boolean flag in your build for whether to include that menu or not, and put it in your production build. Another option is to "hide" it in the UI, perhaps as a long-press on the app logo, something most people won't do, but if you want specific people to have access to it, they can. Then when testing is finished, you do a proper production release and remove it.Disapprove
@Geobert I think it's a bad idea to be sending debug builds to testers, much better to send them production releases. It gives them an experience closer to the end result, e.g. makes sure they're testing a version that's using the production MapView key, for example. Debug builds are for you, production for your testers and end-usersDisapprove
I
38

Many Android projects are starting to use the gradle build system (we transitioned to it when we started using Android Studio). Fortunately, gradle makes it really simple to install both a dev and release version simultaneously, each with their own independent data. The Android docs cover this, just add a applicationIdSuffix to your debug build type like so:

android {
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
    }
}
Insentient answered 2/4, 2014 at 17:30 Comment(1)
I'm not that familiar (yet) with gradle, but at least according to what I've read so far, I think this should be the accepted answer, since it's the best solution to the OP's question.Ezaria
D
4

I'm not aware of any easy way to do get around the uninstall/reinstall process, so your options include...

  • Buy a second device for testing (some Android devices are very cheap now, especially on eBay)
  • Use the emulator for testing

I see the same issue, but it's to be expected, so I use the phone for debug dev, and the tablet for production testing. When I'm close to a release, I test the production version on both devices and the emulator.

With your testers, I'd advise that you always give them release versions, but you could include extensive logging to help with problems. Debug versions are then only used by you, and release versions by them. If you provide testers with a release version, they use, and accumulate data, when they come to upgrade to the next version, the data can be retained (or updated, if you change the schema) to migrate their data.

I don't see a need for your testers to be using debug & release versions.

Disapprove answered 10/2, 2011 at 17:23 Comment(3)
it's because I provide a debug menu with some advanced actions only available when the app is signed wish debug signatureCochleate
In that case I would suggest you add a boolean flag in your build for whether to include that menu or not, and put it in your production build. Another option is to "hide" it in the UI, perhaps as a long-press on the app logo, something most people won't do, but if you want specific people to have access to it, they can. Then when testing is finished, you do a proper production release and remove it.Disapprove
@Geobert I think it's a bad idea to be sending debug builds to testers, much better to send them production releases. It gives them an experience closer to the end result, e.g. makes sure they're testing a version that's using the production MapView key, for example. Debug builds are for you, production for your testers and end-usersDisapprove
S
3

Thanks @Evan your solution works perfect:

android {
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
    }
}

To append " (DEBUG)" to your app title when running in debug mode, place this code in your Activity's onCreate:

PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    //The .debug specified in gradle
    if (pInfo.packageName.equals("YOUR_PACKAGE_NAME_HERE.debug")) {
        setTitle(getTitle() + " (DEBUG)");
}
Senega answered 15/12, 2014 at 21:45 Comment(0)
M
2

Why uninstall the app? Normally, installing the new version of the same app (identified by the package ID) retains all the app data.

EDIT: to retain app data by hand, copy it from /data/data/my.package.name/... to a safe place, then restore when necessary.

Micron answered 10/2, 2011 at 17:7 Comment(10)
The same app will be overwriting the old one while keeping the data, yes, but you can not install a second app with the same package, but a different signing, as @Geobert has. So that's what happens.Countrybred
I did not change the package id but it does not install. I've uninstall the debug version then install the release one. Then when I tried to launch in debug mode from eclipse, it says:Cochleate
[2011-02-10 18:11:24 - radis] Uploading radis.apk onto device '10006609c6cb' [2011-02-10 18:11:24 - radis] Installing radis.apk... [2011-02-10 18:11:25 - radis] Re-installation failed due to different application signatures. [2011-02-10 18:11:25 - radis] You must perform a full uninstall of the application. WARNING: This will remove the application data! [2011-02-10 18:11:25 - radis] Please execute 'adb uninstall fr.geobert.Radis' in a shell. [2011-02-10 18:11:25 - radis] Launch canceled!Cochleate
Oh, debug and release at the same time on the same device? Possible, but only if they introduce different package IDs. Android identifies apps by their package ID.Micron
Is "package ID" the java style package name? Can we change it according to debug/release mode?Cochleate
The one that's listed in the manifest file as <manifest package="...">. Normally matches the Java package name, but does not have to.Micron
Isn't the data folder protected? Don't you need root to access it?Inquisitive
Not sure... My Android users are giving me conflicting reports. Probably varies by device (carrier?) and OS version.Micron
I think this is a bad solution - you should send production APKs to your testers and customers, otherwise they could give feedback, everything is ok, then you release the production build and you see problems. Your testers should be testing a version as close as possible to that you will finally release.Disapprove
I kinda agree; in my case, the beta was signed by prod key, and the debugging features were well-hidden (activated by a cheat code in one of the input fields). Just answering the question.Micron
V
2

Configure the application id suffix

With the following configuration on your app build.gradle, the release variant will use com.example.myapp applicationId, and the debug variant com.example.myapp.debug

android {
    defaultConfig {
        applicationId "com.example.myapp"
        ...
    }
    ...
}
buildTypes {
  debug {
    applicationIdSuffix ".debug"
    ...
  }
  release {
    ...
  }
  ...
}

Configure multiple Firebase Accounts

If you use Firebase, you will need two Firebase accounts, one for production, and the other for development. You have to configure Google Services JSONs for each account on its own variant source set:

  • The production google-services.json on the release source set: app/src/release/google-services.json
  • The development google-services.json on the release source set: app/src/debug/google-services.json

Providers authorities

If you have defined a provider in your AndroidManifest.xml, now you could have a conflict if both release and debug variants use the same provider authorities and you have both apps installed on the same device. To avoid this issue, a good practice is to use the applicationId as the authority suffix.

<provider
   android:name="androidx.core.content.FileProvider"
   android:authorities="${applicationId}.fileprovider"
   android:exported="false"
   android:grantUriPermissions="true">
</provider>

Custom icon for each variant

If you are going to install multiple variants on the same device, a good idea is to use different app icons, so you can identify them on the launcher. You just need to design a debug app icon and locate it on src/debug/res/mipmap-xxhdpi-*

Configure FCM

Now that you use different Firebase Accounts, if you have an FCM (push) server, you will need to configure it with the correct credentials. When a device with the debug app is registered, the FCM server needs to associate the registration token with the debug build type. So, when a push is sent, the token of the Firebase debug credentials is used. So, you will need to send the build type to the FCM server, every time the app registers the FCM token.


The following article gives more info about this topic: Install your debug & release variants on the same device

Vaasta answered 28/6, 2021 at 1:28 Comment(0)
B
1

For me, I also needed to add:

<permission                                                                               
      android:name="${applicationId}.permission.C2D_MESSAGE"                                
      android:protectionLevel="signature" />                                                

<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /> 

Otherwise, both would receive the same C2D_MESSAGE permission which resulted in:

Failure [INSTALL_FAILED_DUPLICATE_PERMISSION perm=<your applicationId>.permission.C2D_MESSAGE pkg=<your applicationId>] 
Brodeur answered 19/4, 2016 at 9:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.