Product Options: Multiple Activities

I am using product options in gradle / android studio to achieve the following project setup:

  • Two applications that are 80% similar in the same Android studio project.
  • Each application should have its own manifest package path (they should basically behave as two independent applications - they have their own google api and push keys)

I followed several tutorials in my attempt to achieve this (placeholders, several manifests), but nothing works.

Following this guide, 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 are my manifest files.

Src / main / manifest:

 <?xml version="1.0" encoding="utf-8"?> 

 <application> </application> 

CSI / 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> 

CSI / 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 install the package for each individual manifest tag, as my application needs different package paths. If I do this anyway, merging will not be able to merge manifest files due to different package values. Apart from packageName, I also tried setting the "applicationId", but that would not work either. Using a placeholder like this package="${applicationId}" does not work because it does not resolve the value of the variable.

Any ideas how to solve this problem? I am using Android Studio 0.8.2 with gradle 0.12.2

+7
android android-studio gradle
source share
4 answers

You can safely add

 <manifest xmlns:android="..." package="com.test.app"> </manifest> 

in your main manifest.

But you should use applicationId , not packageName in your build.gradle. applicationId build.gradle will overwrite this value during your various builds.

The best way to do this would be to use applicationIdSuffix instead of applicationId for your various tastes of the product.

The field must be present in your main manifest.

+3
source share

In addition to your src/app1/AndroidManifest.xml and src/app2/AndroidManifest.xml you will have src/main/AndroidManifest.xml , which can contain elements shared by both applications.

In your manifests specific to your taste, you do not need to specify the package attribute, as this is already defined in your build.gradle .

However, in your main manifest, you need to define the 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 you do not have dependent libraries that also use this name, or you get another build error.

In addition, you need to specify applicationId instead of packageName in build.gradle to separate the package name used to identify your application from the name of the package used for internal access to resources.

Check out this link for more information: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename

+2
source share

I solved the same problem by putting the same package="com.ex.app" in every flavor manifest and pasting applicationId and useOldManifestMerger true in the build.gradle file

 android { useOldManifestMerger true productFlavors{ app1{ applicationId = "com.ex.app1" } app2{ applicationId = "com.ex.app2" } } } 
0
source share

I started a new one, but this time Android Studio generated the Variant configuration for me (in the project settings there is a tab for flavors, options, etc.)

I also decided to change the package name for all three variants with the same name as the identification of each application (variant) is performed by the applicationId application (which has nothing to do with the actual variant package names).

Thanks pdegand59 for the help!

0
source share

All Articles