I have 2 product flavor. Let's say the example like this:
productFlavors {
free {
applicationId 'com.free.android'
}
premium {
applicationId 'com.premium.android'
}
My problem is when i use
Intent resultIntent = new Intent(this, ExpiryListActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ExpiryListActivity.class);
stackBuilder.addNextIntent(resultIntent);
The problem happened when stackBuilder.addParentStack(ExpiryListActivity.class)
The first app which used the productFlavor free doesn't cause android.content.pm.PackageManager$NameNotFoundException
error.
But the second app which used the productFlavor premium it causes android.content.pm.PackageManager$NameNotFoundException
.
Then i read the docs that stackBuilder.addParentStack(<Class>)
Add the activity parent chain as specified by manifest . How to solve this problem?
TL;DR change your metadata as
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="originalPackageName.ui.MainActivity" />
The basic problem is that gradle is expanding the package name for the parent activity class that you wrote in the metadata.
In case of your free product flavor it tries to find a class at location com.free.android.ui.MainActivity
And in case of your paid flavor it tries to find a class at location com.premium.android.ui.MainActivity
But gradle actually does not restructure the packages when you mention different applicationId's for your product flavors and the class is still located at originalPackageName.ui.MainActivity and hence the NameNotFoundException
where originalPackageName is a placeholder for the package name you started your project with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With