Code Obfuscation - Android
The purpose of obfuscation is to reduce your app size by shortening the names of your app’s classes, methods, and fields.
ProGuard
Android ProGuard is a tool to obfuscate, shrink, and optimize your code. Obfuscated code can be more difficult for other people to reverse engineer. ProGuard renames classes, fields, and methods with semantically obscure names and removes unused code.
If you use ProGuard to obfuscate your app that includes the Anyline SDK for Android, you need to turn on ProGuard for release builds and add exceptions for the Anyline SDK in your Proguard config file.
R8 also uses the same ProGuard rules files to modify its default behavior.
PLEASE NOTE:
When building your project using Android Gradle plugin 3.4.0 or higher, the plugin uses the R8 compiler, instead of ProGuard, to handle the following compile-time tasks:
Code shrinking (or “Tree-Shaking”)
Resource shrinking
Obfuscation
Optimization
Turn on ProGuard for release builds in the build.gradle file of the app
Groovy (build.gradle)
android {
//...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Kotlin (build.gradle.kts)
android {
//..
buildTypes {
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
}
Add ProGuard exceptions for the Anyline SDK
To add an exception for the Anyline SDK, you have to add the following lines to your ProGuard config file. In case you used the configuration from the example above, your ProGuard file is called proguard-rules.pro
.
-keep class at.nineyards.anyline.** { *; }
-dontwarn at.nineyards.anyline.**
-keep class org.opencv.** { *; }
-dontwarn org.opencv.**
PLEASE NOTE:
-keep specifies classes and class members (fields and methods) to be preserved as entry points to your code.