Android Studio two flavors with different manifest files - android

I'm having issues with defining two different manifest files for my flavors in Android Studio. This is my current project structure:
The AndroidManifest.xml in the free flavor looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="se.example.package">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>
The AndroidManifest.xml in the main flavor has no uses-permissions, but contains the rest of the manifest code that is shared between all flavors.
The AndroidManifest.xml in the pro flavor looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="se.example.package">
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
</manifest>
build.gradle defines the two flavors like
productFlavors {
free {
applicationId 'se.example.package.free'
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName '1.0'
}
pro {
minSdkVersion 14
applicationId 'se.example.package.pro'
targetSdkVersion 21
versionCode 2
versionName '1.1'
}
}
The result that I am expecting is that the different flavors defines different uses-permissions. This is not the case. The result is currently that the both flavors only defines the <uses-permission android:name="com.android.vending.CHECK_LICENSE" /> as defined in AndroidManifest.xml in the pro flavor.
I have tried:
Clean project
Rebuild project
Restart Android Studio
Sync gradle
But without success. How am I to fix this? Any help is appreciated.
EDIT 1
I changed the location of each flavors AndroidManifest.xml file from each of the res folders to free and pro folder. The result of this:
Pro flavor shows Licence permission as expected.
Free flavor shows permissions from both AndroidManifest.xml
files, License and network permissions (Should be only network)
This feels like an issue of project structure. What to make of this?
EDIT 2
I pulled the merge reports as Commonsware hinted, these are the reports regarding uses-permissions
Free:
uses-permission#com.android.vending.CHECK_LICENSE
ADDED from qwknoteGIT:licencing-library:unspecified:26:5
android:name
ADDED from qwknoteGIT:licencing-library:unspecified:26:22
Pro:
uses-permission#com.android.vending.CHECK_LICENSE
MERGED from qwknoteGIT:licencing-library:unspecified:26:5

Tech background:
on this link it explains the techniques and parameters that can be use for manifest merging: https://developer.android.com/studio/build/manage-manifests#merge_rule_markers
One in specific is the tools:node that points out how certain XML nodes on the manifest should behave whilst merging.
Solution:
to achieve some permisions in one and different in other manifest, add ALL permissions you need to the main and in the flavours manifest remove the ones you don't need, like the example below:
free remove the check license
<uses-permission
android:name="com.android.vending.CHECK_LICENSE"
tools:node="remove"/>

Your problem is coming from a library, not your flavors. Specifically, qwknoteGIT:licencing-library is requesting CHECK_LICENSE.
If you are not using that library in all flavors, use a flavored compile statement (e.g., proCompile) to only use that library in that flavor.
If you are using the library for all flavors, but feel confident that you do not need the permission in one flavor, that's where a tools:node attribute can be used, in the flavor's manifest, to block out that permission supplied by the library.
And the manifest merger report is your friend. :-)

This should solve the problem, at least. I find it useful in specifying the exact manifest to use for each variant. Cheers! It explicitly directs to the manifest file under each variant folder.
android {
productFlavors {
prod {
manifest.srcFile "prod/AndroidManifest.xml"
}
dev {
manifest.srcFile "dev/AndroidManifest.xml"
}
}
...
}

Specify your Manifest exclusively under sourceSets, In your App build.gradle
android {
productFlavors {
bizdartFlavourNoCallLog {
minSdkVersion 16
applicationIdSuffix '.bizdart'
targetSdkVersion 26
dimension "tier"
sourceSets {
main {
manifest.srcFile "src/bizdartFlavourNoCallLog/AndroidManifest.xml"
}
}
copy {
from 'src/bizdartFlavourNoCallLog/'
include '*.json'
into '.'
}
}
}
}

See https://developer.android.com/studio/build/manifest-merge with param tools:node="merge"
High priority manifest (Free):
<activity android:name="com.example.ActivityOne"
android:screenOrientation="portrait"
tools:node="merge">
</activity>
Low priority manifest (Main):
<activity android:name="com.example.ActivityOne"
android:windowSoftInputMode="stateUnchanged">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Merged manifest result:
<activity android:name="com.example.ActivityOne"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateUnchanged">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

You should change your code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="se.example.package">
for:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.your.appid">

I encountered the same problem, and I found that it was because I put "pro" and "tree" flavor folder under the lib project, and the problem was solved after I move the flavors folder under the app project

Related

Android Auto Setup with Gradle Build Flavors

I have a project where I am attempting to add Android Auto support. I have added the following code to my manifest as shown in the Auto documentation:
<application
....
<meta-data android:name="com.google.android.gms.car.application"
android:resource="#xml/automotive_app_desc"/>
....
<service
android:name="com.me.auto.MyMediaBrowserService"
android:exported="false">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
....
</applicaiton>
I'm also using different build flavors, defined in my gradle.build file:
defaultConfig {
applicationId "com.me"
minSdkVersion 16
//noinspection OldTargetApi
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
productFlavors {
regular {
applicationId "com.me"
}
different {
applicationId "com.meother"
}
}
When I build and install using the 'regular' flavor, android auto does not work. However, when I build and install using the 'different' flavor, everything works great. If I then change the regular applicaitonId to something else like 'com.menew', again Auto works great.
How is the applicationId in the build flavor making or breaking Android Auto functionality?
I am not absolutely sure, but I would guess this is related with the application id, e.g. you can make avoid full qualified package names by using the relative names you can use it in the manifest all all places. Check this:
<service
android:name="com.me.auto.MyMediaBrowserService" ...>
vs.
<service
android:name=".auto.MyMediaBrowserService" ...>
Make also sure that you have no hard coded packages in your code always use BuildCondig.APPLICATION_ID when you need your package name.
Looks like you have it mostly right. I would recommend these changes (based on https://developer.android.com/training/auto/audio/index.html) and see if this fixes it.
1) Remove the package name so it's not locked into one flavor. Alternatively, you can use ${applicationId} and gradle will insert the correct one.
2) Set the service to be exported (android:exported=true).
<application
....
<meta-data android:name="com.google.android.gms.car.application"
android:resource="#xml/automotive_app_desc"/>
....
<service
android:name="${applicationId}.auto.MyMediaBrowserService"
android:exported="true">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
....
</applicaiton>
Did you try to create a flavorDimensions?
You can try this.
flavorDimensions "mode"
productFlavors {
regular {
dimension = "mode"
}
different {
dimension = "mode"
}
}
if you want to get the version of your application
if (BuildConfig.Flavor.contains("regular") || BuildConfig.Flavor.contains("different")) {
// Your code goes here.
}
Hope this will help.

Manifest Merger failed with multiple errors in Android Studio

So, I am a beginner into Android and Java. I just began learning. While I was experimenting with Intent today, I incurred an error.
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs
I found some solutions here and tried to implement them, but it did not work.
This is my build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.example.rohan.petadoptionthing"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
}
This is my AndroidManifest :
<?xml version="1.0" encoding="utf-8"?>
package="com.example.rohan.petadoptionthing" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Second"
/>
<activity android:name=".third"/>
<activity android:name=".MainActivity"/>
</application>
This is my first week with coding, I am sorry if this is a really silly thing. I am really new to this and did not find any other place to ask. Sorry if I broke any rules
Open application manifest (AndroidManifest.xml) and click on Merged Manifest tab on bottom of your edit pane. Check the image below:
From image you can see Error in the right column, try to solve the error. It may help some one with the same problem. Read more here.
Also, once you found the error and if you get that error from external library that you are using, You have to let compiler to ignore the attribute from the external library.
//add this attribute in application tag in the manifest
tools:replace="android:allowBackup"
//Add this in the manifest tag at the top
xmlns:tools="http://schemas.android.com/tools"
Remove <activity android:name=".MainActivity"/> from your mainfest file. As you have already defined it as:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
So, Manifest file showing ambiguity.
For me THIS works -
Finding Merging Errors in AndroidManifest.xml
Click on Merged Manifest in AndroidManifest.xml
You can view manifest merging error in right column. It may help to solve this problem.
I was also facing same issues, and after lot of research found the solution:
Your min sdk version should be same as of the modules you are using eg: your module min sdk version is 14 and your app min sdk version is 9 It should be same.
If build version of your app and modules not same. Again it should same
** In short, your app build.gradle file and manifest should have same configurations**
There's no duplicacy like same permissions added in manifest file twice, same activity mention twice.
If you have delete any activity from your project, delete it from your manifest file as well.
Sometimes its because of label, icon etc tag of manifest file:
a) Add the xmlns:tools line in the manifest tag.
b) Add tools:replace= or tools:ignore= in the application tag.
Example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.slinfy.ikharelimiteduk"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="1"
android:versionName="1.0" >
<application
tools:replace="icon, label"
android:label="myApp"
android:name="com.example.MyApplication"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="#drawable/ic_launcher"
android:theme="#style/Theme.AppCompat" >
</application>
</manifest>
If two dependencies are of not same version
example: you are using dependency for appcompat v7:26.0.0 and for facebook com.facebook.android:facebook-android-sdk:[4,5)
facebook uses cardview of version com.android.support:cardview-v7:25.3.1 and appcompat v7:26.0.0 uses cardview of version v7:26.0.0, So there is discripancy in two libraries and thus give error
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Attribute meta-data#android.support.VERSION#value value=(26.0.0-alpha1) from [com.android.support:appcompat-v7:26.0.0-alpha1] AndroidManifest.xml:27:9-38
is also present at [com.android.support:cardview-v7:25.3.1] AndroidManifest.xml:24:9-31 value=(25.3.1).
Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:25:5-27:41 to override.
So by using appcompat of version 25.3.1, We can avoid this error
By considering above points in mind, you will get rid of this irritating issue.
You can check my blog too
https://wordpress.com/post/dhingrakimmi.wordpress.com/23
Just add below code in your project Manifest application tag...
<application
tools:node="replace">
If your project targeted Android 12 then
Add this in all <activity> tags with <intent-filter>
android:exported="true/false"
In addition to available solutions, please check this also.If you have set android:allowBackup="false" in your AndroidManifest.xml then there may be a conflict for android:allowBackup="true" in other dependencies.
Solution
As suggested by #CLIFFORD P Y, switch to Merged Manifest in your AndroidManifest.xml. Android Studio will suggest to add tools:replace="android:allowBackup" in <application /> in your AndroidManifest.xml.
I was facing the same problem and I've just added one line in my manifest.xml and it worked for me.
tools:replace="android:allowBackup,icon,theme,label,name">
add this line under
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#drawable/launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="#style/AppThemecustom"
tools:replace="android:allowBackup,icon,theme,label">
Hope it will help.
I solved this with Refactor -> Migrate to AndroidX
GL
In my case it was showing an error because there was a redundancy in <uses-permission> element.
So, please check in your AndroidManifest.xml file for the same.
Android Studio version is 3.0.1
Operating System is Windows 7
Here is the screenshot for reference.
Usually occurs when you have errors in your manifest.Open AndroidManifest.xml .Click on the merged manifest tab.The errors can be seen there .Also include suggestions mentioned there.When I had a similar problem while importing com.google.android.gms.maps.model.LatLng ,it suggested me to include tools:overrideLibrary="com.google.android.gms.maps" in the application tag and the build was successful.
solution for me was like this:
1- open manifest
2-On top right , check highlighted problems like below:
3-click on problems icon in red. this will open problems tab like below.
4- solve them one by one
I was also facing this error. In the build log the last line was "Failed to compile values file".
So if you're facing the same issue, then just adding the following line in the gradle.properties file will most probably fix the issue.
android.enableJetifier=true
I mean it fixed Manifest Merger failed with multiple errors in Android Studio error for me.
My case i have fixed it by
build.gradle(Module:app)
defaultConfig {
----------
multiDexEnabled true
}
dependencies {
...........
implementation 'com.google.android.gms:play-services-gcm:11.0.2'
implementation 'com.onesignal:OneSignal:3.+#aar'
}
This answer releted to OnSignal push notification
If after you add a Android Library Module and you get this error.
You can fix it by simple remove the android:label="#string/app_name" from the AndroidManifest.xml of your Android Library Module
In AndroidManifest.xml:
At application, add tools:replace="android:icon, android:theme and
At the Manifest root, add xmlns:tools="http://schemas.android.com/tools
In build.gradle:
At root, add useOldManifestMerger true
The minium sdk version should be same as of the modules/lib you are using
For example: Your module min sdk version is 26 and your app min sdk version is 21 It should be same.
I see the answers and they are complete and useful. Anyway, if you are completing the Jetpack Compose Testing codelab and you find this error in late 2021, the solution is not the accepted answer, you need to downgrade your target sdk version to 30.
In app/build.gradle, replace:
targetSdkVersion 31
with:
targetSdkVersion 30
And run the Android Tests again
for the past few days I was also going through the same issue. But after, a lot of research I finally found a solution for this.
In order to solve this issue, what you need to do is:
1. Check if your project's build.gradle file and the module's build.gradle file contain same versions of all dependencies.
2. Make sure, your project's compileSdkVersion, buildToolsVersion, minSdkVersion and targetSdkVersion matches the one in the modules or libraries that you have added into the project.
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.appname"
minSdkVersion 16
targetSdkVersion 25
versionCode 22
versionName "2.0.3"
}
Hope, this helps.
Open your gradle console, then you see gradle suggest you to add the particular line (Like: tools:replace="android:allowBackup" or tools:replace="android:label" etc). Add that line into your manifest file under tag and sync gradle, that's it.
In my case it happened for leaving some empty intent-filter inside the Activity tag
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
</intent-filter>
</activity>
So just removing them solved the problem.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
The following hack works:
Add the xmlns:tools="http://schemas.android.com/tools" line in the
manifest tag
Add
tools:replace="android:icon,android:theme,android:allowBackup,label,name"
in the application tag
I was using the FirebaseUI Library along with the Facebook SDK Library, which was causing me the issue.
implementation 'com.firebaseui:firebase-ui-database:0.4.4'
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
And from [here][1], I got rid of this issue.
With the latest update of FirebaseUI library, previous version of Facebook SDK is also a part of it.
If you are using the both the libraries, please remove the Facebook SDK Library.
https://github.com/firebase/FirebaseUI-Android/issues/230
UPDATE
From the Android Studio 3.0 and the later versions, app.gradle file is required to use implementation or api instead of compile for adding the dependencies to the app.
This error occurs because you don't have proper statements at the Manifest root such:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.test">
So you should remove additional texts in it.
In my case, I solved it by updating the classpath in build.gradle (Project) file to the latest version.
It was like this:
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
After updating to the latest version:
dependencies {
classpath 'com.android.tools.build:gradle:3.5.4'
}
Everything worked fine! Hope this helps someone if all the above answers don't solve the issue.
As a newbie to Android Studio, in my case, I had moved an existing project from Eclipse to Android Studio and found that there was a duplicate definition of an activity within my Manifest.xml that hadn't been picked up by Eclipse was shown as a Gradle error.
I found this by going to the Gradle Console (bottom right of the screen).
Happened with me twice when I refractor (Rename with SHIFT + F6) the name of a field in our files and it asks you to change it everywhere and we without paying attention change the name everywhere.
For example, if you have a variable name "id" in your Java class and you rename it with SHIFT + F6. If you don't pay attention to the next dialog which will ask you wherever else it is going to change the id and you tick check all it will change all the id in your layout files from the new value.
this is very simple error only occur when you define any activity call two time in mainifest.xml file Example like
<activity android:name="com.futuretech.mpboardexam.Game" ></activity>
//and launcher also------like that
//solution:use only one
Put this at the end of your app module build.gradle:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.0'
}
}
}}
from this
Supplement the answer Phan Van Linh. I deleted these lines:
android:icon="#mipmap/ic_launcher"
android:label="name"

uses-sdk is missing in manifest

i am following the Training section of developer.android.com where i can read :
One of the most important elements your manifest should include is the
element.
But, the automaticaly generated manifest i have is :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.david.myapplication" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.david.myapplication.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Where i can't see any .
Must i consider it as normal behaviour ? Must i add this by myself ?
May be usefull : i am using AndroidStudio instead of Eclipse/ADT
Android Studio uses the newer Gradle-based build system. Its manifest merger creates the actual manifest for you, based on the information in the AndroidManifest.xml files and build.gradle files.
In particular, the uses-sdk information is usually derived from build.gradle.
For android studio, the compile sdk version is in the build.gradle. like this:
defaultConfig {
applicationId "com.eyespage.sdk.accounts"
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
so you don't have to include it in manifest

Product Variants: Multiple Activities

I'm using Product Variants in gradle/android studio to achieve the following project setup:
Two apps, that are 80% similar in one android studio project.
Each app should have its own manifest package path (they should basically behave like two independent apps - with it's own google api and push keys)
I've followed multiple tutorials in my attempt to achieve this (placeholders, multiple manifests) but nothing works.
Following this tutorial I did the following:
http://www.kevinrschultz.com/blog/2014/03/23/using-android-content-providers-with-multiple-package-names/
My build.gradle:
android {
compileSdkVersion 19
buildToolsVersion '20'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
app1 {
packageName "com.test.app1"
//applicationId "com.test.app1"
}
app2 {
packageName "com.test.app2"
//applicationId "com.test.app2"
}
}}
And here my manifest files.
src/main/manifest:
<?xml version="1.0" encoding="utf-8"?>
<application>
</application>
src/app1/manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="com.test.app1”
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.test.app1.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
</activity>
</application>
</manifest>
src/app2/manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="com.test.app2”
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.test.app2.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
</activity>
</application>
</manifest>
This gives me the following error message:
Manifest merger failed : Main AndroidManifest.xml at AndroidManifest.xml manifest:package attribute is not declared
Unfortunately I can't set a package to each individual manifest tag as my app requires different package paths. If I do it anyway, the merger is not able to merge the manifest files because of different package values. Besides packageName I also tried setting "applicationId" but this doesn't work, either. Using a placeholder like this package="${applicationId}" doesn't work because it doesn't resolve the variable value.
Any ideas how to solve this problem? I'm using Android Studio 0.8.2 with gradle 0.12.2
You can safely add
<manifest xmlns:android="..."
package="com.test.app">
</manifest>
in your main manifest.
But you have to use applicationId and not packageName in your build.gradle.
The applicationId of the build.gradle will overwrite this value during your different builds.
A better way of doing this would be to use applicationIdSuffix instead of applicationId for your different product flavors.
The field have to be present in your main manifest.
In addition to your src/app1/AndroidManifest.xml and src/app2/AndroidManifest.xml you will have a src/main/AndroidManifest.xml which can contain elements both apps share.
In your flavor-specific manifests, you do not have to specify a package attribute, since that is already defined in your build.gradle.
In your main manifest however, you need to define a package attribute, to specify the package name used for your shared resources:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.app">
</manifest>
Make sure that you do not have any dependent libraries, which is also using that name, or you will get another build error.
Furthermore, you will want to specify applicationId instead of packageName in you build.gradle to decouple the package name used for identification of your app from the package name used for internal resource access.
Check this link for further information: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename
I resolved same issue putting the same package="com.ex.app" in every flavor's manifest and putting applicationId and useOldManifestMerger true into build.gradle file
android {
useOldManifestMerger true
productFlavors{
app1{
applicationId = "com.ex.app1"
}
app2{
applicationId = "com.ex.app2"
}
}
}
I started over fresh but this time Android Studio generated the Variant configuration for me (under project settings there's a tab for flavors, variants, etc.)
I also decided to change the package name of all three variants to the same name as the identification of each app (variant) is done by the applicationId (which has nothing to do with the actual package names of the variants).
Thanks to pdegand59 for his help!

Creating activity-alias for build variants using gradle

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"
}
}
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

Categories

Resources