我無法創建使用不同清單的兩種不同構建類型。即使在使用--rerun任務重新運行gradle並完全刪除build目錄之後,Android中包含的AndroidManifest也不正確。例如,我運行assembleRelease,它包含ReleasePlus構建類型中的AndroidManifest。我想保持項目結構不需要切換到新的src // *結構。我也嘗試過使用產品風味,但是如果不改變結構,這似乎不是一種可能。導入的Eclipse項目 - 具有不同AndroidManifest的Gradle構建類型
的build.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')
}
}
}
}