我正在使用以下风格来改进Android 5及更高版本设备的调试版本:
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 16
}
}
然而,并非所有设备都在api 21+下运行,因此我想控制multiDex和minifying。 E.g:
productFlavors {
dev {
minSdkVersion 21
multiDexEnabled false
minifyEnabled false
}
prod {
minSdkVersion 16
multiDexEnabled true
minifyEnabled true
}
}
但是这给了我:
Error:(44, 0) Could not find method minifyEnabled() for arguments [false] on ProductFlavor_Decorated
如何将这些属性组合在一起?
答案 0 :(得分:2)
minifyEnabled()
仅在BuildType DSL对象中可用。虽然multiDexEnabled
指的是ProductFlavor对象。因此,如果要组合这些属性,则必须在这两个对象中指定它。 E.g:
productFlavors {
dev {
minSdkVersion 21
multiDexEnabled false
}
prod {
minSdkVersion 16
multiDexEnabled true
}
}
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled true
}
}
对于调试版本,使用devDebug
版本变体,用于发布 - prodRelease
。
答案 1 :(得分:0)
正如@maxost所建议的那样
就在下面我已经提供了android开发者链接
请参阅此处[https://developer.android.com/studio/build/multidex.html#dev-build]:
android {
defaultConfig {
...
multiDexEnabled true
}
productFlavors {
dev {
// Enable pre-dexing to produce an APK that can be tested on
// Android 5.0+ without the time-consuming DEX build processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the production version.
minSdkVersion 14
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}