I have a Flutter (3.0.4) app that I run on Android 12 (real device and emulator) for testing.
Main Flutter dependencies are shared_preferences 2.0.15, flutter_riverpod 1.0.4, intl 0.17.0, i18n_extension 5.0.0 and syncfusion_flutter_charts 20.1.58.
Gradle version seems to be 7.1.0 (note: also listed as 4.0.0 for android/build.gradle -> buildscript -> ext -> gradleVersion, so not sure about that).
There is no issue when running in debug mode (flutter run
).
But when running in release mode (flutter run --release
), and switching to the specific app page using charts with SyncFusion, I get the following error displayed directly on the app page:
Note that there is no class "h" in my code.
Following some of the suggestions here and here, I've been trying the following:
- Add lintOptions in android/app/build.gradle -> android {}
- Downgrading Gradle to 3.6 (not fond of that solution, as you can guess, but tried anyway)
- Adding the decorators
@Keep
and/or@Serializable
to the only Kotlin class in my code (I have one custom Kotlin class).
None of those solutions worked. I've been also looking at this, but not sure to understand how it can applies to my case.
I am under the impression that the error comes from SyncFusion Flutter module when building in release mode, since the error appears only on the page using SyncFusion, not any other.
Any idea on what's happening?
CodePudding user response:
It's most probably caused by proguard
and minifyEnabled
. It might obfuscate/optimize some code that shouldn't.
In my case, I was using a custom aar
android library in my flutter app. And the public interface of the library data models were affected.
To solve this issue, I added in my flutter app's build.gradle
:
buildTypes {
release {
signingConfig signingConfigs.release
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro' # and this line
}
}
And then I created a file proguard-rules.pro
in the same directory as the build.gradle
:
-keep class com.android.library.dataModels.** { *; }
-keep class com.android.library.publicInterface.** { *; }
I also added the same things in my aar
. Both were required.
You could also totally remove minifyEnabled
(minifyEnabled false
) and proguard
. This should emphasize the issue.