fix(app): release builds keep JNI-called plugin code, so settings, sign-in and drafts are saved on the phone
This commit is contained in:
@@ -32,6 +32,11 @@ android {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig = signingConfigs.getByName("debug")
|
||||
// Keeps JNI-called plugin code (see proguard-rules.pro).
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
# Flutter plugins whose Dart side calls Java/Kotlin through JNI (jni/jnigen,
|
||||
# e.g. shared_preferences_android, path_provider_android). R8 cannot see those
|
||||
# calls, so it would strip or rename the methods and every call fails at run
|
||||
# time with NoSuchMethodError (saved settings, sign-in and drafts were lost).
|
||||
-keep class io.flutter.plugins.** { *; }
|
||||
-keep class com.github.dart_lang.jni.** { *; }
|
||||
-keep class kotlin.** { *; }
|
||||
-keep class kotlinx.coroutines.** { *; }
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('release builds keep the plugin code called through JNI', () {
|
||||
// Without these rules R8 strips shared_preferences' JNI targets and a
|
||||
// release phone loses every saved setting, sign-in and draft.
|
||||
final gradle = File('android/app/build.gradle.kts').readAsStringSync();
|
||||
final rules = File('android/app/proguard-rules.pro').readAsStringSync();
|
||||
expect(gradle, contains('"proguard-rules.pro"'));
|
||||
for (final rule in [
|
||||
'-keep class io.flutter.plugins.** { *; }',
|
||||
'-keep class com.github.dart_lang.jni.** { *; }',
|
||||
'-keep class kotlin.** { *; }',
|
||||
]) {
|
||||
expect(rules, contains(rule));
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user