how to manage debug and release version on android device?

浪子不回头ぞ 提交于 2019-12-02 23:46:40

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.

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

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

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.

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