我有一个具有多种产品风格的应用程序,每种风格都有自己的applicationId,每种风味都需要自己的AndroidManifest.xml。这些产品风格具有库依赖性。在清单合并期间,库的包名称与flavor的包名称冲突,但我似乎无法找到使其工作的安排组合。
这是我对图书馆的清单:
<manifest package="com.mylibrary">
</manifest>
这是我对productFlavor的清单:
<tools:manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="com.flavor1.permission.C2D_MESSAGE" />
<permission android:name="com.flavor1.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.flavor1.MAPS_RECEIVE"/>
<permission
android:name="com.flavor1.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<application
android:vmSafeMode="true"
android:name="com.mylibrary.Application"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.mymainapp.MainActivity"
tools:node="remove"/>
<activity
android:name="com.flavor1.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</tools:manifest>
这是我的基础应用程序的gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId 'com.myapp'
minSdkVersion 21
targetSdkVersion 23
versionCode 409
versionName "v4alpha9"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
dataBinding {
enabled true
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
res.srcDirs = ['src/main/res']
java.srcDirs = ['src/main/java']
}
flavor1 {
res.srcDirs = ['src/productFlavors/flavor1/res']
java.srcDirs = ['src/productFlavors/flavor1/java']
manifest.srcFile 'src/productFlavors/flavor1/AndroidManifest.xml'
}
flavor2 {
res.srcDirs = ['src/productFlavors/flavor2/res']
java.srcDirs = ['src/productFlavors/flavor2/java']
}
}
productFlavors {
flavor1 {
applicationId 'com.flavor1'
}
flavor2 {
applicationId 'com.flavor2'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':mylibrary')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.mindscapehq.android:raygun4android:2.1.0'
compile 'com.android.support:support-v4:23.4.0'
}
我的错误是:
错误:任务':myapp:processFlavor1DebugManifest'的执行失败。 清单合并失败:属性工具:清单@包值=(com.flavor1)来自(未知) 也出现在[android:mylibrary:unspecified] AndroidManifest.xml:3:5-44 value =(com.mylibrary)。 元素的属性未合并。