I need to make different flavors for test libraries. Why? Well, I want project to be fully secured so I wanna minifying to be enabled all the time(even for debug build type).
While making tests I'm using different classes from project, so I decided to change proguard files using flavor. It looks like something this :
android {
...
buildTypes {
release {
minifyEnabled true
testProguardFile 'test-proguard-rules.pro'
}
debug {
minifyEnabled true
testProguardFile 'test-proguard-rules.pro'
}
}
...
productFlavors{
forTest{
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules1.pro', 'debug-rules.pro'
}
forRelease{
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'debug-rules.pro'
}
}
}
And proguard-rules* files
proguard-rules:
-dontwarn blablabla.**
-dontwarn blabla.**
-keep class bla.** { *; }
proguard-rules1:
-dontshrink
-dontobfuscate
-dontwarn
But this wasn't helpful for me. I want to run tests without obfuscation. Flavors doesn't have such param as minifyEnabled so I try to find any solution. So any suggestions about resolving an issue? May be someone had the same problem and find another solution (not using flavors) ?
For example, you may want to explicitly tell ProGuard which classes to keep. To do this, create a new .cfg file and apply the ProGuardConfiguration build action in the Properties pane of the Solution Explorer: Keep in mind that this configuration file does not replace the Xamarin.Android proguard_xamarin.cfg file since both are used by ProGuard.
One important item to know in advance before using ProGuard is how it works within the Xamarin.Android build process. This process uses two separate steps: Each of these steps is described next. The Xamarin.Android linker employs static analysis of your application to determine the following: Which assemblies are actually used.
Optionally, you can add a custom ProGuard Configuration file to exert more control over the ProGuard tooling. For example, you may want to explicitly tell ProGuard which classes to keep. To do this, create a new .cfg file and apply the ProGuardConfiguration build action in the Properties pane of the Solution Explorer:
1.Proguard in Normal project with one module. In Android when we create a Project we get a file created inside our project structure with the name proguard-rules.pro Once we start adding up the code and new features we use few third-party libraries also, and once we move forward towards release we add up respective Proguard rules.
After a whole day messing with this I found the following works:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
flavorA {
applicationIdSuffix ".a"
proguardFile 'flavorA_rules.pro'
}
flavorB {
applicationIdSuffix ".b"
}
}
More info: Include additional configurations
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