4

I'm using Android Studio 2.1.3 (Mac OS X) and com.android.tools.build:gradle:2.1.3. I've already tried invalidating cache and restarting and clean builds.

I have a project with many ProductFlavors, all of which use the same starting activity save one (this one is a paid version that uses the licensing library, all the others are free so I don't bother, although a solution might just be to use the licensed version of the activity for all flavors but skip the licensing unless a resource is set... just seems too easy to hack). I thus have 2 AndroidManifest.xml files:

// app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.company.app">
    ...
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
                 android:label="@string/appFriendlyName"
                 android:theme="@style/AppTheme">

        <activity
            android:name="com.company.app.TabsFragmentActivity"
            android:screenOrientation="portrait"
            android:label="@string/appFriendlyName">
            <intent-filter android:label="@string/launcherLabel">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    ...
    </application>
</manifest>


// app/src/PaidFlavor/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.company.app">
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
                 android:label="@string/appFriendlyName"
                 android:theme="@style/AppTheme">

        <activity
            tools:node="merge"
            android:name="com.company.app.TabsFragmentActivityLicensed"
            android:screenOrientation="portrait"
            android:label="@string/appFriendlyName">
            <intent-filter android:label="@string/launcherLabel">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            tools:node="remove"
            android:name="com.company.app.TabsFragmentActivity"/>
    </application>
</manifest>

This works great, and I can inspect the generated intermediate (merged) AndroidManifest.xml, and indeed the TabsFragmentActivity activity is removed, and the TabsFragmentActivityLicensed is added, and all is right with the world.

But I don't want the debug version (build type) to be licensed. Again, I can work around it easy enough in code, but it's the principle of the matter! So I thought it would be easy to just move

app/src/PaidFlavor/AndroidManifest.xml

to

app/src/PaidFlavorRelease/AndroidManifest.xml

This is where things go wrong. Everything builds without error, and I look at the intermediate (merged) manifest and it still looks correct. However, Android Studio tries to launch the PaidFlavor with release build type as:

adb shell am start -n "com.company.project/com.company.app.TabsFragmentActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Wrong activity! Where's it getting it from? Am I using the wrong subdirectory (PaidFlavorRelease/)? This results in the obvious error:

Error while executing: am start -n "com.company.project/com.company.app.TabsFragmentActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.company.project/com.company.app.TabsFragmentActivity }
Error type 3
Error: Activity class {com.company.project/com.company.app.TabsFragmentActivity} does not exist.

Error while Launching activity
Oded
  • 954
  • 12
  • 16

0 Answers0