0

I just finished setting up build variants with Gradle in Android Studio. What a blessing this will be for a typical demo/pro setup. I'm able to launch my 'demoDebug' app perfectly fine. When I switch to 'proDebug' and 'Run" with the same configuration it installs the pro app fine but crashes launching it:

Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid } Error type 3 Error: Activity class {com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid} does not exist.

If I then go to the dashboard I can launch the pro version and it works as expected. So the install works for the appropriate version; there's only something wrong in the launch (on pro).

build.gradle flavors:

productFlavors {
    demo {
        packageName "com.anthonymandra.rawdroid"
    }

    pro {
        packageName "com.anthonymandra.rawdroidpro"
    }

    proAmazon {
        packageName "com.anthonymandra.rawdroidpro"
    }
}

Update

cleaned up extraneous info unrelated to the issue

When I decompiled the apk I confirmed that none of the gradle overrides were being implemented in the Android.manifest.

Anthony
  • 7,638
  • 3
  • 38
  • 71
  • Include your project structure shown in Android studio in question. – Piyush Agarwal Feb 17 '14 at 06:33
  • Added, though I can confirm the structure is correct since the pro build properly pulls the custom code and it executes properly when launched via the hardware dashboard. It's just an issue with the run configuration launch, though I don't see what should be changed for different variants. – Anthony Feb 17 '14 at 06:54
  • try to use flavour packagename in the manner like (your originalpackageneme.falvorName) eg. : (com.anthonymandra.rawdroid.demo) and (com.anthonymandra.rawdroid.pro) and let me know if it works. – Piyush Agarwal Feb 17 '14 at 08:05
  • Error: Activity class {com.anthonymandra.rawdroid.demo/com.anthonymandra.rawdroid.RawDroid} does not exist. The launch error appears to exist for demo as well if I attempt to change the packageName. – Anthony Feb 17 '14 at 09:07
  • Something wrong in your manifest, I tried in my machine it is working fine. What I found is gradle updates your manifest automatically while compilation as your earlier compilation was not correct make sure you have defined activity in manifest properly or not. – Piyush Agarwal Feb 17 '14 at 09:34
  • If possible include your complete manifest file in the question. – Piyush Agarwal Feb 17 '14 at 09:37
  • Check my answer and we will continue this on answer instead of question if doesn't help. – Piyush Agarwal Feb 17 '14 at 09:57

2 Answers2

1

First you should have packagename in manner like (recommended approach not mandatory ):

youractualapplicationpackage.flavorname

But you can have packagname whatever you want for flavours like in your case:

productFlavors {
    demo {
        packageName "com.anthonymandra.rawdroiddemo"
    }

    pro {
        packageName "com.anthonymandra.rawdroidpro"
    }

    proAmazon {
        packageName "com.anthonymandra.rawdroidpro"
    }
}

make sure com.anthonymandra.rawdroid is the application's java package inside your main/java directory.

Your AndroidManifest.xml should be like this(Only inside main directory):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.anthonymandra.rawdroid" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
      android:name=".RawDroid"
      android:configChanges="keyboardHidden|orientation|screenSize"
      android:label="@string/app_name"
      android:theme="@style/GalleryTheme" >
        <intent-filter>
           <action android:name="android.intent.action.MAIN" />

           <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
 </activity>

</application>

</manifest>

And it should be only in the main directory not anywhere else.

At compilation time gradle will do the necessary package name changes and will make the build.

Same worked fine in my machine and I was able to see two different apps in my device for two different flavors.

Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
  • Still have the error following your directions. Even if the packageName did fix it, it would cause an issue uploading to play since the app is already released and I can't change the package name. – Anthony Feb 17 '14 at 14:43
  • PackageName is not an issue the one posted is recommended thing. Itried excly what yours is and working fine for me. Same thing happend no change. Check my edit in package names. Your manifest must only be in main directiory with main's package name. Do the changes and Cleat project and rebuild. – Piyush Agarwal Feb 17 '14 at 14:55
  • this shows `{com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid}` your manifest is wrong. Please include your complete manifest bro. – Piyush Agarwal Feb 17 '14 at 15:04
  • Included the manifest header. It's 300 lines long, so including the complete manifest would be extreme ;-). – Anthony Feb 17 '14 at 15:47
  • 1
    That works perfectly. I'm currently doing an exhaustive compare on both projects. – Anthony Feb 18 '14 at 01:25
0

The issue was:

'manifestmerger.enabled=false'.

I disabled the function a while back because it caused issues with a library. In the meantime I forgot about it, but apparently the library merging also applies to the gradle merging. I suppose that makes some sense but they really need to allow for separation between gradle merging and library merging.

Thanks to @pyus13 for nonstop support till I came to the typical "Oh s---, are you kidding me..."

Anthony
  • 7,638
  • 3
  • 38
  • 71