Crashlytics - different package names for different gradle flavours - android

I am trying to setup an Android app, using Android Studio with 2 different flavours. Each flavour changes packageName and applicationId - since I want 2 separate APK's submitted as 2 different products to Google Play.
I also try to setup separate apps in Crashlytics, one for each flavour. Although the first one was created without any problem, when I switch flavour, Crashlytics plugin for Android Studio still thinks that my project is already setup. So currently I cannot setup my Crashlytics for second flavour properly.
Thanks in advance for any suggestions.

As suggested by m4ch3t3 this workaround worked perfectly:
I created an empty project with package name matching the other
flavour. Using this project I created new app in Crashlytics. Then I
compiled both flavours of my real project and caused fake crashes in
them. Crashes were reported into matching Crashlytics apps
You can define different package name by definining applicationId in your app build.gradle as follow:
productFlavors {
dev {
applicationId "dev.myapp.app"
}
prod {
applicationId "prod.myapp.app"
}
}

Using the Crashlytics plugin for Android Studio will be a PITA in your case.
What you really need is only the API key and secret - shared among the same organisation - so if you already have one app correctly deployed on Crashlytics you can access those data from your organisation profile.
Just log out from the android studio plugin (CTRL+L while the plugin popup is focused), and take a look at this answer that explain how to deal with multiple flavour and multiple keys.

Related

Firebase android distribution won't allow applicationIdSuffix

When running ./gradlew appDistributionUploadDevDebug I get an error saying it can't find the app.
The culprit is having applicationIdSuffix = ".dev" in my dev flavor. Removing it allows the apk to be uploaded, but then the artifact wouldn't be built properly. For the record I plan using only the dev flavor for internal distribution.
I get an error message saying I should enable app distribution, but since this is done on a "firebase project" level and it's done for the main flavor I can't do it again.
* What went wrong:
Execution failed for task ':app:appDistributionUploadDevDebug'.
> App Distribution could not find your app 1:xxxxxxxxx:android:0b3f<xxxxxxxxx>.
Make sure to onboard your app by pressing the "Get started" button on the App Distribution page in the Firebase console:
https://console.firebase.google.com/project/_/appdistribution
Documenting this as a bug, I'll add a reply since I found a workaround.
Edit: expanded name of gradlew task that was shortened. Though it works it may make for easier searching.
Workaround:
To fix open app/google-services.json and look for the mobilesdk_app_id key for the main package name.
For example in my case I noticed that 1:xxxxxxx:android:0b3f<xxxxxxx> was the value for the package with the .dev suffix, while the main package name (without .dev) shows under 1:xxxxxxx:android:7eb88<xxxxxxxx>
So heading to app/build.gradle, the firebaseAppDistribution block would look like this
firebaseAppDistribution {
appId = "1:xxxxxxxx:android:7eb88<xxxxxxxx>"
I still think this is a bug in firebase distribution. Sounds like the distribution gradle code is picking the right value, but the distribution server is not compatible.
BTW When the developer wants/needs to have 2 separate firebase projects you need to download 2 separate google-services.json files, and place them in the appropriate flavor folders. I also have a (2nd and 3rd) app that shares a project with that setup, but haven't added firebase distribution yet to check how it behaves.
For reference, my workaround worked while providing a serviceCredentialsFile. I also tried using the web token authentication but my results were inconclusive.
I thought that would be the case, but it turns out that you have to enable app distribution for each apk (buildType and/or flavor).
When selecting a project on the firebase console, the page automatically selects one of the apps and I was just enabling app distribution for that one.
There's a dropdown at the top where you can select another app (build/flavor), and you have to go to each one individually and enable app distribution.
I hope this helps someone else.

Differentiate crash reporting between debug and production builds

I'm setting up Firebase Crashlytics for my Android app, and I would like the crash reports for the debug version to be separate from all other versions.
There are several copies of the auto-generated values.xml file (that is generated when the google-services plugin processes toe google-services.json file) located in the different retrospective buildType folders. One of the strings contained in the files is:
<string name="google_crash_reporting_api_key" translatable="false">{API-KEY}</string>
The API key is the same for each buildType, so I'm thinking if I can just create a new API key for the debug version, it'll solve the problem but how to do this? Or is there another way (that doesn't involve changing the applicationId as I can't do this)?
I've searched the android docs, looked up other articles and looked through other SO answers but no luck.
Any help welcomed, thank you.
You cannot differentiate the crash as per the build type (debug version).
You have to create a new project in the firebase with same app details (package name).
Get the API key for the project and then replace that key in your manifest file and DONE.
You just have to replace the key when you change your build Type.

Fabric Crashlytics stuck on build and run

Currently, I'm trying to integrate Crashlytics into an Android Application. However I can't get the app to be recognized and added to the Fabric Dashboard.
When using the Android Studio Fabric plugin following these steps:
New App
Select Crashlytics
Apply Code changes
Sync gradle
Rebuild project
Build app onto device (not virtual)
However when I do this, the Fabric plugin is still stuck on the "Please build and run your application" screen, and eventually gives an error message "It's been a while. Need some help?"
I've also attempted to install Crashlytics manually, by adding the code myself using this link: https://fabric.io/kits/android/crashlytics/install
But when I build the application, still nothing happens within my Fabric Dashboard.
I've attempted checking out the branch again and re-adding this code to no avail. I've also tried reinstalling the Fabric IDE plugin, restarting Android Studio and Restarting my machine.
I have successfully added Crashlytics to other applications following these same steps.
Any ideas?
I just had the same problem - nothing happened in the Fabric-plugin screen saying "Please build and run your application" during app-launches.
It started working after I disabled Instant Run (Preferences > Build Execution Deployment > Instant Run) then rebuilt and run the app.
Probably you forgot to add apply plugin: 'io.fabric' in start of your app level gradle.build file
I have had a similar problem - month ago I refactored package name and inserted wrong char to name (cyrillic с instead of latin c), what I only have seen now by viewing java code in hex-editor. In the build.gradle applicationId = "package name" was write similar as package name in *.java files, but only all chars were the right in latin.
Simple refactoring app package name to right name that equals the appliationId and clean/build project not solve that problem with the Fabric Crashlytics. May be wrong package name stay in another files, not only in *.java, manifest and gradle. I don`t know. Because I made fully refactoring by next step:
1) delete all lines of code that was added by Fabric plugin (if you used automatic code inserting) or that was added by you manually from build.gradle (app), AndroidManifest.xml, MainActivity.java.
2) replace old package name to new by Edit>Find>Replace in Path
3) manually copy all minimal needed project files to new project folder. I copyed these folder and files
NewProjectFolder/build.gradle
NewProjectFolder/app/build.gradle
NewProjectFolder/app/src/*
NewProjectFolder/app/libs/*
4) close current project, at "Welcome to Android Studio" select Import Project and select project in new project folder.
5) make some refactoring to run your app normally (I use Firebase, therefore I add this new app to my Firebase project in Firebase console and download the new google-services.json to NewProjectFolder/app/ )
6) be sure your app runs as well as before refactoring and stop it
7) start Fabric plugin, press "+New App" > "Crashlytycs" > "Install" > "Apply" to make auto-install fabric`s code to your build.gradle (app), AndroidManifest.xml, MainActivity.java.
8) run your app and wait "Done!" on Fabric plugin. After this you can see your app in Crashlytics dashboard.
It has worked for my project and I hope help to you.
I also had this problem. Make sure you rename your application package identically to what the application ID is.
For instance, I had the package structure com/exampleapp/, but it should have been com/companydomain/appname, because the application id was com.companydomain.appname
Have same issue here, i resolve doing these things:
First, add at your app build.graddle file:
defaultConfig {
applicationId "<your package name>"
}
If that doesnt resolve, try change your applicationId to other one, that doesnt match with your package.
For some reason, they worked here.
Also had this issue, then
I refactored my application package name
and
changed application id name in gradle
built it again and the issue was solved.
Make sure to include all dependencies on their dedicated gradle.build and meta in manifest file. Next is to throw a force runtime error on your device with internet connection also do not forget to initialize it first with Fabric.with(this,new Crashlytics()). If this doesn't work try to download Fabric for Android plugin in Android Studio and select your package.
This helped me:
https://developer.android.com/studio/build/optimize-your-build#disable-crashlytics-build-id
If you want to use Crashlytics with your debug builds, you can still
speed up incremental builds by preventing Crashlytics from updating
app resources with its own unique build ID during every build. Because
this build ID is stored in a resource file that is referenced by the
manifest, disabling automatic build ID generation also allows you to
use Apply Changes alongside Crashlytics for your debug builds.
To prevent Crashlytics from automatically updating its build ID, add the following to your build.gradle file:
android {
...
buildTypes {
debug {
ext.alwaysUpdateBuildId = false
}
}

how to installed apk without uninstalling the current apk of the same App

I used to work with Android studio 1.4. yesterday I downloaded the newest version of android Studio 2.1.2 and it did not work well for me, so i reverted to Android studio 1.4.
the problem is, when i tried to run my App, I received a message telling me, "that the apk is already installed on the phone and to reinstall it i have to uninstall the version that is already on the phone".
Actually, I can not uninstall the apk version that is currently on the phone because it contains a huge database, and if i uninstalled it, then the databse content will be lost and i have to do it from the beginning
is there any other solution to run the App "apk" without uninstalling it
i am getting this message:
The easiest and the fastest way is to change application package name.
An appropriate way to do what you want would be to use ProductFlavours.
You start by adding the following to your app's build.gradle:
android {
productFlavors {
dev {
applicationId "com.yourapp.dev" //one in development mode
}
prod {
applicationId "com.yourapp" //the package name for your released app
}
}
}
You can add parameters different for the dev and production apk(s) as BuildConfig fields.
Do study more about it, will be able to implement it in the way you want. You can start with
Mastering product flavours on android
Just change the applicaitonId property in the app module's build.gradle.
Change version code and version name in build.gradle.
Hope this will help you.
1-First of All Please Change Your Current Application Package name
2-Build The Application
3-We can't use same package name in android
4-Work Will File after completion this steps.
Just change the applicaiton's Id property which is located in the app module's build.gradle.

How to build 2 apps with the same project in android studio?

I've recently just imported my eclipse project into Android Studio, I haven't convert it into gradle yet. So some forum that offers me solution from gradle is not working. My problem is I have 2 application, where both has some slight difference. I want to use the same project when I deploy the application. I've tried to change the project name but that doesn't help. The moment the new application is installed, the previous version is overwritten. I thought of making some changes to the Manifest file(not sure if this is the right thing to do) but in android studio, I can't seem to locate where the file is. Please help.
Regards,
Dexter
Your application needs to have a different package name for it to be treated as a different app.
So instead of
com.yourcompany.apps.yourapp
You write
com.yourcompany.apps.yourapp1 and
com.yourcompany.apps.yourapp2
You can do that in your AndroidManifest.XML in the manifest tag
package="com.yourcompany.apps.yourapp1"
Also, instead of 2 separate apps, try seeing if you can solve this using Build variants and product flavors.
Use flavors on your build.gradle
productFlavors {
flavorName {
minSdkVersion 19
applicationId 'you.package.name'
targetSdkVersion 23
versionCode 1
versionName 'version_name'
}
}
Also you can modify a file with different changes by just adding a source folder for the flavor.
app
|--src
|--main
|--flavorName

Categories

Resources