diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro new file mode 100644 index 0000000..a08a582 --- /dev/null +++ b/android/app/proguard-rules.pro @@ -0,0 +1,16 @@ +# Flutter 的 release 构建默认开启 R8 混淆(本文件存在时会自动加入 proguardFiles)。 +# +# shared_preferences 等插件用 JNIGen 生成 Dart 绑定,Dart 侧按「类名 + 方法名 + +# 描述符」字符串查找 Java 方法,描述符里含 kotlin.coroutines.Continuation 等 +# 类型名。R8 把它们改名(实测 Continuation -> vd)后运行期就抛 NoSuchMethodError, +# SharedPreferences 整体失效:壁纸保存不上,主题、服务器列表也无法持久化。 +# debug 不开 R8,所以只有 release 出问题。 + +# Kotlin 标准库类名会出现在 JNIGen 的方法描述符里 +-keepnames class kotlin.** + +# suspend 方法的末端参数,名字写死在 Dart 绑定里,连成员一起保留最稳妥 +-keep class kotlin.coroutines.Continuation { *; } + +# Dart 侧按全限定类名查找插件类(如 SharedPreferencesApiRegistrar) +-keepnames class io.flutter.plugins.** { *; } diff --git a/lib/features/settings/settings_page.dart b/lib/features/settings/settings_page.dart index 7859dcc..bb01ec7 100644 --- a/lib/features/settings/settings_page.dart +++ b/lib/features/settings/settings_page.dart @@ -128,8 +128,7 @@ class _SettingsPageState extends State { if (!mounted) return; // 通过 Provider 落盘并通知,背景层随之交叉淡入 - await context.read().setCustomWallpaper(path, type: 'image'); - _refreshUI(); + if (await _applyWallpaper(path, 'image')) _refreshUI(); } Future _pickVideo() async { @@ -143,8 +142,24 @@ class _SettingsPageState extends State { if (path == null) return; if (!mounted) return; - await context.read().setCustomWallpaper(path, type: 'video'); - _refreshUI(); + if (await _applyWallpaper(path, 'video')) _refreshUI(); + } + + /// 落盘壁纸设置。失败时给出可见提示,避免「点了没反应」式的静默失败 + /// (例如 release 包把插件方法混淆掉、SharedPreferences 整体不可用时)。 + Future _applyWallpaper(String path, String type) async { + try { + await context.read().setCustomWallpaper(path, type: type); + return true; + } catch (e) { + debugPrint('保存壁纸设置失败: $e'); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('壁纸设置保存失败,请重试')), + ); + } + return false; + } } Future _saveFileToAssets(String sourcePath, String type) async {