I cannot effectively exclude classes from code obfuscation in the final apk using flutter for android.
I am developing a plugin that wraps some native android code / libraries and provides some flutter classes. That package is then used by a flutter application I'm developing.
This is important because previously everything was on one project and the native code was called via the channel and there was no problem with the native library. But since I moved that code inside a plugin, an issue with code obfuscation prevents me from using the library. The core library, which is proprietary, seems to load a class by name and throws an exception because all my classes in the final apk are given pseudo-random letter names. The problem presents itself only in release mode.
This is to say that the problem is 100% obfuscation. So, it would make sense to me to play with the proguard rules. I am aware that flutter uses r8 by default and it cannot be disabled, but from my understanding it should still interpret .pro files and the syntax should be the same.
However, by inspecting the apk with the android studio tool, the class.dex file contains only obfuscated stuff except something from google and from a barcode library.
The gradle in my app looks like this (I tried some variants, like adding the default file):
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled true
proguardFiles 'proguard-rules.pro'
}
}
the proguard file (desperately trying to exclude everything in order to see something in the released apk):
-keep class com.example.printer.** { *; }
-keep class com.example.myapp.** { *; }
-dontshrink
-dontoptimize
I also tried to add a copy of that proguard file in the android folder of my plugin (is this required?). I tried to build both with "flutter run --release" and "flutter build apk --release --no-shrink"
Apparently the extension .pro was causing the issue. Txt seems to work just fine. Therefore, the gradle now looks like this:
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled true
proguardFiles 'proguard-rules.txt'
}
}
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