[求助]为什么 flutter 调试模式可以。发布模式打包出来的则无法运行。

2 天前
 Dnlyao
环境使用 gradle-7.5-all.zip ,
buildscript {
ext.kotlin_version = '1.9.10'
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
google()
mavenCentral()
maven { url "https://jitpack.io" }//maven 仓库
}

dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
使用 flutter_blue: ^0.8.0 依赖。发布模式查看不到什么报错。然后再调试模式,正常调起蓝牙服务。
150 次点击
所在节点    Flutter
2 条回复
Dnlyao
2 天前
在真机编译运行。
lutter ( 7085): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Field state_ for t2.i not found. Known fields are [private int t2.i.e, private static final t2.i t2.i.f, private static volatile r1.a1 t2.i.g], null, java.lang.RuntimeException: Field state_ for t2.i not found. Known fields are [private int t2.i.e, private static final t2.i t2.i.f, private static volatile r1.a1 t2.i.g]
E/flutter ( 7085): at r1.v0.n0(Unknown Source:72)
E/flutter ( 7085): at r1.v0.T(Unknown Source:698)
E/flutter ( 7085): at r1.v0.R(Unknown Source:12)
E/flutter ( 7085): at r1.k0.e(Unknown Source:60)
E/flutter ( 7085): at r1.k0.a(Unknown Source:49)
E/flutter ( 7085): at r1.d1.d(Unknown Source:17)
E/flutter ( 7085): at r1.d1.e(Unknown Source:4)
E/flutter ( 7085): at r1.z.A(Unknown Source:4)
E/flutter ( 7085): at r1.z$a.C(Unknown Source:9)
E/flutter ( 7085): at r1.z$a.B(Unknown Source:0)
E/flutter ( 7085): at t2.a.a(Unknown Source:775)
E/flutter ( 7085): at j3.k$a.a(Unknown Source:17)
E/flutter ( 7085): at w2.c.l(Unknown Source:18)
E/flutter ( 7085): at w2.c.m(Unknown Source:40)
E/flutter ( 7085): at w2.c.i(Unknown Source:0)
E/flutter ( 7085): at w2.b.run(Unknown Source:12)
E/flutter ( 7085): at android.os.Handler.handleCallback(Handler.java:958)
E/flutter ( 7085): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 7085): at android.os.Looper.loopOnce(Looper.java:257)
E/flutter ( 7085): at android.os.Looper.loop(Looper.java:368)
E/flutter ( 7085): at android.app.ActivityThread.main(ActivityThread.java:8839)
E/flutter ( 7085): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 7085): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
E/flutter ( 7085): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
E/flutter ( 7085): )
E/flutter ( 7085): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652)
E/flutter ( 7085): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310)
E/flutter ( 7085): <asynchronous suspension>
E/flutter ( 7085): #2 FlutterBlue.state (package:flutter_blue/src/flutter_blue.dart:56)
E/flutter ( 7085): <asynchronous suspension>
E/flutter ( 7085): #3 AppBleService.init.<anonymous closure> (package:weight_app/services/app_ble.dart:40)
E/flutter ( 7085): <asynchronous suspension>
E/flutter ( 7085):
Dnlyao
2 天前
貌似找到问题了,可能是 flutter 混淆把依赖的 class 搞丢了。现在配置了保护,就能正常了。
proguard-rules.pro 位置 android\app\proguard-rules.pro
-ignorewarnings
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }

-keep class * {
public private *;
}

android\app\build.gradle 也需要修改,设置规制文件
buildTypes {

release {
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // 自定义混淆规则文件
}

}
_____
不知道是不是真的这个原因。要等有空才能确定......

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1088864

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX