Reputation: 1000
I recently merged 4 similar but independent apps into one gradle project and setup gradle to use build variants for deploying each one independently. Because I've merged these projects that were previously independed, I needed to rename some packages, including the package for the launcher activity. In order to preserve the launcher links for my current user base, I wanted to use an activity-alias to point the old launcher links to the new launcher activity. So far so good.
However, since I have multiple build variants, I need several different aliases to link back to the new launch activity. I looked into gradle's new manifest merging solution and looked into using placeholders for the alias name, however, when I drop the placeholder under the alias, it refuses to acknowledge the right package. The app will crash with
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.stuart.android.flavor1/${packageName}.NewLauncherActivity }
Error type 3
Error: Activity class {com.stuart.android.flavor1/${packageName}.NewLauncherActivity} does not exist.
Below is the activity-alias from my manifest and the gradle build file. I need to find a way to insert the package name for each build variant into the alias for each build I do. com.stuart.android.main is the common package among all flavors and is the location of the new launch activity. I'm using Android Studio 0.6.1 with the 0.11 Gradle plugin. Any help is appreciated!
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stuart.android.main"
android:installLocation="auto">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:allowBackup="true" android:theme="@style/appTheme">
<activity android:name=".NewLauncherActivity" android:label="@string/app_name_full"/>
<activity-alias
android:name="${packageName}.OldLauncherActivity"
android:targetActivity="com.stuart.android.main.NewLauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
</application>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/>
</manifest>
build.gradle
productFlavors {
flavor1 {
packageName "com.stuart.android.flavor1"
}
flavor2 {
packageName "com.stuart.android.flavor1"
}
flavor3 {
packageName "com.stuart.android.flavor1"
}
flavor4 {
packageName "com.stuart.android.flavor1"
}
}
Upvotes: 4
Views: 2195
Reputation: 21
As You use Gradle to set the "packageName" (or "applicationId"), You may try
android:name="com.stuart.android.main.NewLauncherActivity"
instead of
android:name=".NewLauncherActivity"
in line 7 of Your Manifest
Upvotes: 2