Crashlytics add new applicationIdSuffix - android

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

Related

Android ANR in MyFirebaseInstanceIDService just in one product flavor

In my app I have two product flavors. Both of them used to work fine. Suddenly I started to get ANR error when I try to run the application and the app freezes during start up. The error in Logcat is:
ANR in com.myapp.development
PID: 7937
Reason: executing service com.myapp.development/com.myapp.development.service.MyFirebaseInstanceIDService
The method MyFirebaseInstanceIDService.onTokenRefresh is never called. The app freezes before any of my own code is executed.
The production flavor still works fine.
Everything in the Firebase console is set up correctly. The app is in the Play Store and both flavors used to work.
productFlavors {
production {
applicationId 'com.myapp'
dimension "default"
}
development {
applicationId 'com.myapp.development'
dimension "default"
}
}
As you can see the only difference between the two flavors is the application id. And if I change the application id in the developmnet flavour it starts to work (the app does not freeze).
I tried the following tests:
I change the package id of the development flavor by adding just one letter: 'com.myapp.developmentX'. I also make the corresponding change in google-services.json file . Then the development flavor also starts. But of course Firebase services do not work, because the new application id is not configured in Firebase console.
In the manifest file I remove the MyFirebaseMessagingService and MyFirebaseMessagingService and MyFirebaseInstanceIDService. Then the app still freezes at start up, but the error in logcat changes slightly:
ANR in com.myapp.development
PID: 683
Reason: executing service com.myapp.development/com.google.firebase.iid.FirebaseInstanceIdService
I checked out an old git branch and tried to start it but the problem is still there.
I also tried: Uninstall the app and install again. Clean project. Delete the build directories. Restart the test device. Use the Android emulator. Restart the computer. Restart Android Studio. Update Android Studio to the latest 3.1.4 for Mac. But non of these helped.
It looks like the problem has something to do with the application id and Firebase, but I cannot find what.
Anyone has any ideas?
Update after comments from Shark and sebasira.
In Firebase console I have one single project and there are two applications defined for it - one for each flavour. In that case there is no need of multiple google-services.json, one for each flavour. The file is the same for all flavours and can be places in the root directory :
app/
google-services.json
The file structure is like that:
{
"project_info": {...},
"client": [...],
}
As you see, there is an array of clients. All application IDs (all flavours) are defined in that array. That's why if I download from Firebase the google-services.json file for each application, they are all the same.
Anyway, I tried to put a different google-services.json file for each flavor like that:
app/src/
flavor1/google-services.json
flavor2/google-services.json
But that didn't help.
I was facing exactly same issue, and my app configuration was also exactly similar as yours.
The issue was caused by the latest Facebook SDK I was using in my code, it crashes the Firebase before the app start hence the app goes to ANR.
I set my Facebook SDK version as 4.35.0 and that solved the issue.
Try it out and let me know if it was helpful.

Fabric/Crashlytics on Android - How to have two different crashlytics projects with the same package name?

I am developing an Android application and I want to have two different projects in Crashlytics / Fabric (debug and release).
I know that this is possible by having two different package names, but in my case, the package name of these two build types have to be the same.
Is there any possibility to have two crashlytics projects with the same package name?
Hello I also had same questions months ago and I solved it myself. Hope my answer will help you.
You need 2 organizations with different crashlyticsApiKey for each of your project on fabric.
Then on your build.gradle file you will define manifestPlaceHolders
debug {
manifestPlaceholders = [crashlyticsApiKey: 'your_api_key_for_debug_project_here']
}
release {
manifestPlaceholders = [crashlyticsApiKey: 'your_api_key_for_release_project_here']
}
Then you will put this variable on meta-data at your AndroidManifest.xml file
<meta-data
android:name="io.fabric.ApiKey"
android:value="${crashlyticsApiKey}" />
That's all, now build your project both for relase and debug, you will see your app will registered for 2 different fabric account with same package nam
There is also an option where you do not need to create multiple organizations. You can use the Fabric.Builder with appIdentifier(java.lang.String appIdentifier).
The only thing to do is replace the Crashlytics initialization from the documentation
Fabric.with(this, new Crashlytics());
with something like this:
final String trackingId = BuildConfig.APPLICATION_ID + ".tv";
Fabric fabric = new Fabric.Builder(this).kits(new Crashlytics()).appIdentifier(trackingId).build();
Fabric.with(fabric);
The second snippet uses projects APPLICATION_ID (package name) and adds a ".tv" to it.
NOTE: when you track your crashes this way, Crashlytics does not create the project by itself. It is important to have the project created manually (or having the project already created from another App with the same package name).

Android “Not_Market_Managed” error

I have published my app in alpha mode. But i am getting this response while licensing my application. I have set the test accounts as well.I have set the License Test Response as "Licensed". But still getting the Not_Market_Managed error.Please help
Make sure you have incremented your version code in your app build.gradle file. If you are trying to publish a new version of your app and the version code is the same, you cannot publish.
I had a similar story. In my case, I added a new flavor and applicationIdSuffix so the package name changed. I thought that the problem was that the application was not uploaded into the play market but when uploading it got an error :
"Upload failed
Your APK needs to have the package name _my_old_packagename_ ". Then I commented out the applicationIdSuffix and the problem was solved. The application did not even need to be uploaded since the application ran under the published account.

Why my signed apk crashes?

I've signed an app with a sign which I've created. I've installed this apk in my phone and this is ok, but when I've tried to open the app crashes (doesn't show any activity), and it doesn't give me the posibility to watch the log (this dialog doesn't have the report button)
The problem is the sign which I've signed the app. I've tested with other sign and the app opens perfectly. I can't post any information about the creation of the sign, but only I can say I've used:
Letters and _ character in alias
Letters, numbers and - character in password
50 in years
and Letters in name
others field are blank.
The main problem is that the app is published in the google play, so How I can publish a new signed apk without to unpublish this app and create a new app?
Cleaning the project solved the problem in my case.
For anyone getting this in a react-native environment, remember to bundle your js before generating the signed APK.
Easy to forget if you're using something like Android Studios GUI 🙃
Delete "gen" folder from the Project then Cleaning the project
In my case, I had to change the minifyEnabled to false in build.gradle
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
You can see this publish APK and its details like version code and version name and etc. in you developer account on google play
There is one button "Upload new APK"
Click on "Upload new APK" Button
Upload new sign APK with bug fixed
deactive current APK
Active new apk
Note : Don't change package name for new APK
Another possible cause (as was the case for me) is using the wrong JDK/JRE version when building your signed APK.
If you're using Eclipse, check Window -> Preferences -> Java -> Installed JREs and see which one is checked as the default. Android is not yet compatible with Java 8.
I had the same problem today and for me it turned out the reason was:
I used void blaMethod() in my Java code which I tried to call by onClick methods of XML Buttons. I had to learn that these methods need to be public void ... - I usually do that, but this time I got a little sloppy.
The strange thing is: my unsigned APK worked perfectly fine on all my devices, but the signed one just crashed when using those methods (could not find method (view) in a parent or ancestor context). Don't get why that is...
May this help someone!
Greets
You can simply create a new keystore if you are in testing
Or simply in my case retype the password

how to manage debug and release version on android device?

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

Categories

Resources