how to manage debug and release version on android device? - android

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?

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

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.

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.

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

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

Related

Trying to connect Huawei IAP SDK for Inapp payments - 6003 error

I'm trying to connect Huawei IAP SDK for Inapp payments. After adding an app in developer console and some inapp items, I tried to run Iap.getIapClient(activity).isBillingSupported method, but got com.huawei.hms.support.api.iap.json.IapApiException: 6003 error. Can't get any information about that status code, what does it mean. Does anybody know something about it?
I had the same problem and here is the fix. The error clearly says that 6003 -> StatusCode.CERT_FINGERPRINT_ERROR. It looks like Huawei can't validate the originality of the app, because of the missing certificate.
You either didn't added agconnect to your project or you're running in a different build type (like debug, that was my issue because I added agconnect several days ago).
If you didn't added the agconnect to your project, make sure you add it. There is an official tutorial how to add it, but here is it in a nutshell:
First of all you need to add the agconnect dependency to your project, download the agconnect-services.json file from Huawei's Developer (from your App). You need to obtain a SHA256 fingerprint with keytool and add this long fingerprint to your Huawei's Developer field.
https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/iap-configuring-appGallery-connect#certificate
If you added agconnect (like I did several days ago) and the error persisted, it was because you were running in debug or any other build type which is different than what your official release. If you're running in debug make sure you add the signing certificate to your debug build type.
signingConfigs {
release {
storeFile file('C:\\path-to-your\project\signing-certificate.jks')
keyAlias 'aliasOfYourCertificate'
keyPassword 'theKeyPasswordOfCertificate'
storePassword 'theStorePasswordOfCertificate'
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
}
}
So the key here is adding the signingConfig to your debug build type (if you're running in debug).
Check whether the certificate fingerprint is correctly configured on HUAWEI Developer. Sign into HUAWEI Developer, go to Management Center > My Products, and select the services that require fingerprint certificate. In the product service list, check whether the SHA256 certificate fingerprint is same as the one you obtained. If not, modify the SHA256 certificate fingerprint, then clear the HMS cache.
If the issue persists, contact HUAWEI support.
Resource: https://developer.huawei.com/consumer/en/service/hms/catalog/huaweiid.html?page=hmssdk_huaweiid_api_reference_errorcode

Crashlytics add new applicationIdSuffix

I’m working on CI for android app and for those purpose I’ve created test app.
I’ve added Crashlytics support and a little bit later productFlavors to the app.
My initial package name was ‘com.kagarlickij.myapplication’ ,
Flavours add applicationIdSuffix to the package name (http://prntscr.com/hm0u3s) and result is e.g. ‘com.kagarlickij.myapplication.staging’
If I build app with package name ‘com.kagarlickij.myapplication’ it uploads to Crashlytics fine,
But if I build app with package name ‘com.kagarlickij.myapplication.staging’ new app doesn't appear in Crashlytics.
In both cases console output doesn't have any errors - http://prntscr.com/hm0svq
build.gradle (and the whole app) - https://github.com/kagarlickij/MyApplication/blob/dev/0.3.0/app/build.gradle
Why it goes like this and how it can be fixed?
The answer turned out to be very simple, but not very obvious - you have to run app built with new flavor in emulator at least once and will become available on Crashlytics - http://prntscr.com/hm25sa

How to load same android app to device with different name

Our company has developed a android app for our customer. I want to create a new app with different name with same source code. I have already changed the app name. But when ever I load this new app to my device from android studio it gives error saying "alredy a new version of app is running in your device".
I want to release the same app with different name to the app store.
If you use android studio, use flavors to compile your app using different packages and different names
Have a look on this website : http://tools.android.com/tech-docs/new-build-system/build-system-concepts
change package name of application in manifest also change app name.
An addition to the other answers here is an example for how to do this:
android {
defaultConfig {
// your config
applicationId "com.packagename.appname"
}
productFlavors {
release {
// you config
applicationIdSuffix "release"
}
debug {
// you config
applicationIdSuffix "debug"
}
}
}
for more, feel free to read this manual

How to configure android map sdk v2 to use different keys for production and development?

I want to automatically set different android map api V2 keys for development and production.
Log in to Google APIs Console
Under "Simple API Access" click "Edit Allowed Android apps..." on the right side
Enter one SHA-1 fingerprint per line like the instructions say:
"One SHA1 certificate fingerprint and package name (separated by a semicolon) per line. Example:
45:B5:E4:6F:36:AD:0A:98:94:B4:02:66:2B:12:17:F2:56:26:A0:E0;com.example
45:B6:E4:6F:36:AD:1A:98:94:B4:02:66:2B:12:17:F1:56:26:A0:E0;com.example"
Now, just use the same "Simple API key" and it'll work for your debug and publish certificate without having to change anything.
I may be wrong, but I think you can use the same V2 API key for both development and production builds. In your Google APIs Console, after generating a simple Android key, you just need to enter the SHA-1 fingerprints of your production signing key, and all the development Android debug signing keys you may have. Then in your manifest, just use that simple Android key and the app should work for both debug and production builds.
One of the easiest solution.You can achieve it with two simple steps.
Add custom value to manifestplaceholders build.gradle file.
See below
buildTypes {
debug {
manifestPlaceholders = [ mapApiKeyValue:"GHjaSyAjlyp3O831lgaonHMXsd-_DpQ3002x3S4"]
}
release {
manifestPlaceholders = [ mapApiKeyValue:"AIzaSyAuMGDLr2HeuRed4JA0CrdYYdZRjeC3EA"]
}
}
Edit manifest file like below.
part of my manifest file
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="${mapApiKeyValue}" />
This solution works for the latest Android 5.0 and Android 6.0 (API 20, 21,22,23)

Install "dev" build of Android app along side market version

I just released my first Android Application through the market. I'm currently working on some new features for the next release and would like to install this "dev build" on my phone, without uninstalling the "production" version (among other things, this will stop future updates from the Market).
I'm especially interested in this because I'd like to give the APK to friends / "beta-testers" to try, but I don't want them to uninstall the released application first.
Is there anyway to have on one device two applications: "App (via market)" and "App (DEV)"
Would this involve using a different signing key or modifying the manifest in someway?
Thanks!
You can simply rename the package, so both apps are installed.
You need to change the package name in the manifest as well as in the source folder. Use Eclipse's refactoring for it and it will be done in a minute.
They don't need to be signed with the same key.
Using Gradle this is very easy. Here's an excerpt from one of my gradle files:
android {
// ...
defaultConfig {
resValue "string", "app_name", "<app name>"
// ...
}
buildTypes {
release {
// ...
}
debug {
resValue "string", "app_name", "<app name> (debug)"
applicationIdSuffix ".debug"
// ...
}
}
}
The key part for allowing another installation is using the applicationIdSuffix that is set in the debug build. Under the hood this basically does the same thing as proposed in Force's answer; it changes the application id of your app.
Setting the resValue app_name allows us to have different app names as well, this makes it much easier to keep track of which installation is which (since both application would get the same name otherwise).
Don't forget to remove the app_name from your strings.xml and fill in your own app name instead of <app name> if you decide to set the app_name in the gradle file like I did above.

Categories

Resources