我有一个引用~100K方法的应用程序,最小Sdk = 16
这是两个组装选项:
现在我有一些常见的用例:
你们有没有关于组装策略的建议?
3 / Prod
2 /测试
1 / Debug
这是Gradle文件:
productFlavors {
dev {
minSdkVersion 21
multiDexEnabled ???
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
multiDexEnabled false
}
}
defaultConfig {
applicationId "xxxx"
targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
versionCode ANDROID_BUILD_VERSION_CODE
versionName ANDROID_BUILD_APP_VERSION_NAME
}
buildTypes {
release {
debuggable false
ext.enableCrashlytics = true
renderscriptOptimLevel 3
signingConfig android.signingConfigs.release
zipAlignEnabled true
minifyEnabled true
// shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
renderscriptOptimLevel 3
applicationIdSuffix ".debug"
versionNameSuffix "debug"
minifyEnabled false
}
}
答案 0 :(得分:2)
Based on the proposal of @Muzikant, that I mainly agree, I summarized my today vision
MultiDex
if you can.
My recommendations are:
as there are 3 builds cases, just make 3 buildTypes :
use 2 flavors:
minSdkVersion
of your app minSdkVersion
(faster building, more features for testing, easier to use espresso...)do not obfuscate for debugging
for using Proguard during the test phase, a specific keyword of the Gradle DSL is necessary testProguardFile('proguard-rules-test.pro')
point the build that will be used for debugging with testBuildType = "validation"
do obfuscate for testing (at least for UI system and functional tests on your CI system)
use the optimisation Proguard rules only for release getDefaultProguardFile('proguard-android-optimize.txt')
, for testing and debug just use getDefaultProguardFile('proguard-android.txt')
The architecture of my Proguard files is the following:
one main file for release proguard-rules-release.pro
that include a set of dedicated Proguard files with -include proguard-rules-fabric.pro
one second file for debug proguard-rules-debug.pro
that include proguard-rules-release.pro
one third file for debug proguard-rules-dontobfuscate.pro
that disable obfuscation
one forth file for testing proguard-rules-test.pro
that include proguard-rules-debug.pro
and the rules necessary for testing
Here is the Gradle file:
android {
...
compileSdkVersion ANDROID_BUILD_SDK_VERSION
buildToolsVersion ANDROID_BUILD_TOOLS_VERSION
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
multiDexEnabled false
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
multiDexEnabled false
}
}
defaultConfig {
applicationId "x.y.app.z"
targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
versionCode ANDROID_BUILD_VERSION_CODE
versionName ANDROID_BUILD_APP_VERSION_NAME
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
// point thge build for testing
testBuildType = "validation"
buildTypes {
release {
debuggable false
ext.enableCrashlytics = true
renderscriptOptimLevel 3
signingConfig android.signingConfigs.release
zipAlignEnabled true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules-release.pro'
}
debug {
debuggable true
renderscriptOptimLevel 3
applicationIdSuffix ".debug"
versionNameSuffix "debug"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro', `proguard-rules-dontobfuscate.pro`
}
validation.initWith(debug)
validation {
signingConfig android.signingConfigs.release
debuggable false
renderscriptOptimLevel 3
applicationIdSuffix ".test"
versionNameSuffix "test"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro'
testProguardFile('proguard-rules-test.pro')
}
}
...
}
I still have some open points to solve :
How to use the automatic debug signing of Android Studio for the validation build ? (but I'm not sure about the impact)
I still have to add proguardFiles
attribute in the validation BuildType while I have the testProguardFile('proguard-rules-test.pro')
that include the debug !
答案 1 :(得分:1)
我在调试版和发行版上都使用了proguard,以避免使用multidex。
我的build.gradle
文件看起来像这样:
debug {
minifyEnabled true
proguardFiles 'proguard_debug.pro'
signingConfig signingConfigs.debug
debuggable true
}
release {
minifyEnabled true
proguardFiles 'proguard_release.pro'
signingConfig signingConfigs.release
debuggable false
}
为了最大限度地减少调试和发布之间的差异,并允许正确调试调试版本,proguard_debug.pro
文件包含以下proguard指令:
-include proguard_release.pro
-dontobfuscate
-dontoptimize
-keep class my.package.name.** {*; }
这样,我只维护一个proguard配置(在proguard_release.pro
中),调试版本使用相同的配置构建,但不会混淆代码。
该配置解决了所有提到的问题: