我无法创建使用不同清单的两种不同构建类型。即使使用 --rerun-tasks 重新运行 gradle 并完全删除构建目录,apk 中包含的 AndroidManifest 也是不正确的。例如,我运行 assembleRelease,它包含来自 ReleasePlus 构建类型的 AndroidManifest。我想保持项目结构不变,而不必切换到新的 src//* 结构。我也尝试过使用产品风味,但如果不改变结构,这似乎是不可能的。
构建.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
signingConfigs {
myConfig {
storeFile file("app.keystore")
...
}
}
buildTypes {
release {
runProguard true
proguardFile 'proguard.flags'
signingConfig signingConfigs.myConfig
buildConfig 'public final static boolean PLUS = false; public final static String PROVIDER_AUTHORITY = "com.app.settings";'
}
debug {
buildConfig 'public final static boolean PLUS = false; public final static String PROVIDER_AUTHORITY = "com.app.settings";'
}
debugPlus.initWith(buildTypes.debug)
debugPlus {
packageNameSuffix '.plus'
buildConfig 'public final static boolean PLUS = true; public final static String PROVIDER_AUTHORITY = "com.app.plus.settings";'
sourceSets {
main {
manifest.srcFile 'AndroidManifestPlus.xml'
java.srcDirs = ['src', 'src-plus']
res.srcDirs = ['res', 'res-plus']
}
debugPlus.setRoot('build-types/debugPlus')
}
}
releasePlus.initWith(buildTypes.release)
releasePlus {
packageNameSuffix '.plus'
buildConfig 'public final static boolean PLUS = true; public final static String PROVIDER_AUTHORITY = "com.app.plus.settings";'
sourceSets {
main {
manifest.srcFile 'AndroidManifestPlus.xml'
java.srcDirs = ['src', 'src-plus']
res.srcDirs = ['res', 'res-plus']
}
releasePlus.setRoot('build-types/releasePlus')
}
}
}
}