V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Dnlyao
V2EX  ›  Flutter

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

  •  
  •   Dnlyao · 9 天前 · 290 次点击
    环境使用 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 依赖。发布模式查看不到什么报错。然后再调试模式,正常调起蓝牙服务。
    5 条回复
    Dnlyao
        1
    Dnlyao  
    OP
       9 天前
    在真机编译运行。
    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
    Dnlyao  
    OP
       9 天前
    貌似找到问题了,可能是 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' // 自定义混淆规则文件
    }

    }
    _____
    不知道是不是真的这个原因。要等有空才能确定......
    whevether
        3
    whevether  
       6 天前
    ext.kotlin_version 这种写法在新版 flutter 中过时了吧。 新版本是写在 settings.gradle 中了. 这种可能导致其他的依赖无统一使用指定的 kotlin 编译。
    whevether
        4
    whevether  
       6 天前
    flutter_blue 而且你这个包也过时了啊。三年前更新的。 还是更新到新版 flutter_blue_plus 吧。要不然后期升级更加工作量巨大。
    Dnlyao
        5
    Dnlyao  
    OP
       6 天前
    @whevether 以前同事搭的模板,flutter 一升级上去,好多不兼容。可能后面会换 plus 吧。太多东西要改了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3771 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 19ms · UTC 10:26 · PVG 18:26 · LAX 02:26 · JFK 05:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.