Building an Android App’s ‘Flavor’ in AIDE
Building an App’s Flavor is way damn easy in the Android Studio but in AIDE… 😵
Its not that easy to understand if you are a beginner!
I was, untill yesterday 😛
Its not toooo complicated, just follow the instructions.
I am guessing that you already have a project loaded in AIDE, then click on ‘Add to Project’ > ‘Add a Flavor’ > Your Flavor Name > Ok!
Now navigate to your App level ‘build.gradle’ & specify a different “applicationId” to your flavor.
Choc {
applicationId "com.example.app.flavored"
minSdkVersion 16
targetSdkVersion 26
versionCode 28
versionName "2.8"
}
}
Okay, so now check your Build Variants by clicking on Menu > Project > Build Variants…
You should see 6 Variants!
The first part Successfull! Now choose your Flavor that you just created > Ok > Build…
So now when you Install & Start the App, there may be a chance that it will Crash! or may even open up nicely but won’t let you navigate through other Activities…!
Why did this happen?
So, if you check the Logcat then you’ll see something like this –
Have you declared the Activity in AndroidManifest?
But then you check the Manifest & all the Activities are Declared…
Now What!?
The Issue here is that if you declare your Activities without adding the package name at prefix, it will crash on your Flavor Build…
For example: This is your original app package name: com.example.app
& this is your flavored package name:
com.example.app.flavored
If you have declared your Activities like below in your Manifest –
android:name=".MainActivity"
android:label="@string/app_name" >
then Change it to –
android:name="com.example.app.MainActivity"
android:label="@string/app_name" >
These Changes are made only to the main module of the App i.e. Original App & not Flavored…
In this way, change all your activity names in Manifest.
The Reason why does this happen –
When you specify Activities without package name in prefix (.MainActivity) instead of full activity path (com.example.app.MainActivity),
AIDE overrides the
to
in your Flavored App’s Manifest…
so your Activity is renamed to
which doesn’t exist & you get a Crash!
Hopefully, I encountered this last night & thought of writing it here as it may be helpfull for someone 😊