Skip to content

Adjust build.gradle for Android API 31 or higher compatibility and dependency updates - #147

Open
devappsteam wants to merge 9 commits into
Yukams:masterfrom
devappsteam:master
Open

Adjust build.gradle for Android API 31 or higher compatibility and dependency updates#147
devappsteam wants to merge 9 commits into
Yukams:masterfrom
devappsteam:master

Conversation

@devappsteam

Copy link
Copy Markdown

Updated compileSdkVersion and targetSdkVersion to 31.

Fixed duplicated kotlin-gradle-plugin declaration.

Replaced jcenter() with mavenCentral() due to JCenter shutdown.

Kept support for Kotlin 1.7.20 and Gradle 7.3.0.

Tested versions:

  • Flutter 3.29.3
  • Dart 3.7.2
  • Android Platform 35
  • JDK 21

Successfully built release APK using flutter build apk --release.

@Anderson-Andre-P

Anderson-Andre-P commented May 29, 2025

Copy link
Copy Markdown

Issue with R8/ProGuard when using GSON TypeToken on Android (Flutter)

Hello @devappsteam and @sultan18kh! First of all, thank you for the great work in updating this package. 👏

I ran into an issue when building in release mode with background_locator_2 in a Flutter project with R8/ProGuard enabled. The error was:

java.lang.IllegalStateException: TypeToken must be created with a type argument: new TypeToken<...>() {}; 
When using code shrinkers (ProGuard, R8, ...) make sure that generic signatures are preserved.

This happens because R8/ProGuard removes generic type information, which breaks GSON's TypeToken functionality.

I was able to fix the issue by adding the following rule to my proguard-rules.pro:

# Preserve generic signatures required by GSON TypeToken
-keepattributes Signature, InnerClasses, EnclosingMethod

It might be helpful to include this in the package documentation or ProGuard section to prevent others from facing the same problem.

For reference, here’s my working proguard-rules.pro file:

# PROGUARD RULES - BACKGROUND_LOCATOR_2

# Background Locator 2 (main plugin)
-keep class yukams.app.background_locator_2.** { *; }

# GSON (for JSON serialization)
-keep class com.google.gson.** { *; }
-keepclassmembers,allowobfuscation class * {
    @com.google.gson.annotations.SerializedName <fields>;
}

If you have any suggestions on how to fix this without needing to modify proguard-rules.pro, please let me know.

Thanks again for the update on package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants