我在 gradle/android studio 中使用 Product Variants 来实现以下项目设置:
- 两个应用程序,在一个 android studio 项目中 80% 相似。
- 每个应用程序都应该有自己的清单包路径(它们基本上应该像两个独立的应用程序一样 - 使用它自己的 google api 和按键)
我已经遵循了多个教程来尝试实现这一点(占位符、多个清单),但没有任何效果。
按照本教程,我做了以下事情:http: //www.kevinrschultz.com/blog/2014/03/23/using-android-content-providers-with-multiple-package-names/
我的 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"
}
}}
这里是我的清单文件。
源/主/清单:
<?xml version="1.0" encoding="utf-8"?>
<application>
</application>
src/app1/清单:
<?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/清单:
<?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>
这给了我以下错误消息:
Manifest merger failed : Main AndroidManifest.xml at AndroidManifest.xml manifest:package attribute is not declared
不幸的是,我无法为每个单独的清单标签设置一个包,因为我的应用程序需要不同的包路径。如果我仍然这样做,则由于包值不同,合并无法合并清单文件。除了 packageName 我还尝试设置“applicationId”,但这也不起作用。使用这样的占位符是package="${applicationId}"
行不通的,因为它不能解析变量值。
任何想法如何解决这个问题?我正在使用带有 gradle 0.12.2 的 Android Studio 0.8.2