diff --git a/packages/shared_preferences/shared_preferences_android/CHANGELOG.md b/packages/shared_preferences/shared_preferences_android/CHANGELOG.md index 78426a1415f7..a6e63f0b4e2e 100644 --- a/packages/shared_preferences/shared_preferences_android/CHANGELOG.md +++ b/packages/shared_preferences/shared_preferences_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.5.2 + +* Fixes a `NoSuchMethodError` at startup in Android release builds by adding consumer R8 rules that keep the Kotlin classes looked up through JNI. + ## 2.5.1 * Updates `androidx.datastore:datastore` to 1.2.1. diff --git a/packages/shared_preferences/shared_preferences_android/android/build.gradle.kts b/packages/shared_preferences/shared_preferences_android/android/build.gradle.kts index f532a28bdcc1..a205cdd91fea 100644 --- a/packages/shared_preferences/shared_preferences_android/android/build.gradle.kts +++ b/packages/shared_preferences/shared_preferences_android/android/build.gradle.kts @@ -49,6 +49,9 @@ android { defaultConfig { minSdk = 24 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + // TODO(https://github.com/dart-lang/native/issues/3732): Remove, along with + // consumer-rules.pro, once package:jni ships the Kotlin keep rules. + consumerProguardFiles("consumer-rules.pro") } lint { diff --git a/packages/shared_preferences/shared_preferences_android/android/consumer-rules.pro b/packages/shared_preferences/shared_preferences_android/android/consumer-rules.pro new file mode 100644 index 000000000000..c7f463fd296e --- /dev/null +++ b/packages/shared_preferences/shared_preferences_android/android/consumer-rules.pro @@ -0,0 +1,14 @@ +# Kotlin classes that package:jni and the generated Dart code look up by name +# through JNI. Classes generated by Pigeon are annotated with @Keep, but library +# classes can't be annotated, so without these rules R8 renames them in release +# builds and the JNI calls fail with NoSuchMethodError. +# +# TODO(https://github.com/dart-lang/native/issues/3732): Delete this file and +# its consumerProguardFiles entry in build.gradle.kts once package:jni ships +# these rules. +-keep class kotlin.Unit { *; } +-keep class kotlin.Result { *; } +-keep class kotlin.Result$Failure { *; } +-keep class kotlin.coroutines.Continuation { *; } +-keep class kotlin.coroutines.intrinsics.CoroutineSingletons { *; } +-keep class kotlin.coroutines.intrinsics.IntrinsicsKt { *; } diff --git a/packages/shared_preferences/shared_preferences_android/pubspec.yaml b/packages/shared_preferences/shared_preferences_android/pubspec.yaml index b922807aa958..d41fa27d904b 100644 --- a/packages/shared_preferences/shared_preferences_android/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences_android/pubspec.yaml @@ -2,7 +2,7 @@ name: shared_preferences_android description: Android implementation of the shared_preferences plugin repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22 -version: 2.5.1 +version: 2.5.2 environment: sdk: ^3.12.0