I have an app that reference ~ 100K methods, with min Sdk = 16
Here is 2 option for assembling:
Now I have some common use cases:
Do you have guys some recommandation about the assembling strategy ?
3/ Prod
2/ Test
1/ Debug
Here is the Gradle file :
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
}
}
In the obfuscation step, ProGuard renames classes and class members that are not entry points. In this entire process, keeping the entry points ensures that they can still be accessed by their original names. The preverification step is the only step that doesn't have to know the entry points.
ProGuard is a tool to help minify, obfuscate, and optimize your code. It is not only especially useful for reducing the overall size of your Android application as well as removing unused classes and methods that contribute towards the intrinsic 64k method limit of Android applications.
ProGuard is an open source command-line tool that shrinks, optimizes and obfuscates Java code. It is able to optimize bytecode as well as detect and remove unused instructions.
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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With