how to manage debug and release version on android device?

不想你离开。 提交于 2019-12-03 09:18:59

问题


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?


回答1:


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.




回答2:


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"
        }
    }
}



回答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)");
}



回答4:


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.




回答5:


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>] 


来源:https://stackoverflow.com/questions/4960235/how-to-manage-debug-and-release-version-on-android-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!