【问题标题】:Flutter app crash on startup with release apk, but runs fine with 'flutter run'使用发布 apk 启动时 Flutter 应用程序崩溃,但使用“flutter run”运行良好
【发布时间】:2020-09-29 19:55:21
【问题描述】:

flutter/移动开发新手。不得不做一些研发才能在移动应用程序中获得我需要的东西,我被困在了终点线的尽头。即让我的 .apk 在实际设备上工作。

我尝试使用flutter install 安装应用程序并将build\app\outputs\apk\release\app-arm64-v8a-release.apk 转移到我的设备上。 应用安装成功,但启动时立即崩溃。

另一方面,它可以在模拟器和物理设备 (s10+) 上使用 flutter run 构建和运行良好

构建

flutter build apk --split-per-abi --obfuscate --split-debug-info=/MyApp/
Running "flutter pub get" in Myapp...                          0.8s
Removed unused resources: Binary resource data reduced from 494KB to 479KB: Removed 2%
Removed unused resources: Binary resource data reduced from 494KB to 479KB: Removed 2%
Removed unused resources: Binary resource data reduced from 494KB to 479KB: Removed 2%
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                      75.5s
√ Built build\app\outputs\flutter-apk\app-armeabi-v7a-release.apk (6.0MB).

没有计划在 Play 商店上发布它,它必须在内部使用,我在工作的最后阶段被困住了。有什么建议可以解决这个问题?

更新

Logcat 设置为错误

2020-09-30 00:00:12.918 2472-9529/? E/pageboostd: prefetch start : app comstsltdstevenspin
2020-09-30 00:00:12.919 507-507/? E/audit: type=1400 audit(1601420412.917:20565): avc:  denied  { search } for  pid=2472 comm="pageboostd" name="com.stsltd.stevenspin" dev="sda31" ino=1708995 scontext=u:r:pageboostd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SM-G975F_10_0020 audit_filtered
2020-09-30 00:00:12.919 507-507/? E/audit: type=1400 audit(1601420412.917:20566): avc:  denied  { search } for  pid=2472 comm="pageboostd" name="com.stsltd.stevenspin" dev="sda31" ino=1708995 scontext=u:r:pageboostd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SM-G975F_10_0020 audit_filtered
2020-09-30 00:00:12.921 2472-9529/? E/pageboostd: comstsltdstevenspin, amt 48201728 scnt 15 fcnt 35
2020-09-30 00:00:12.921 2472-9529/? E/pageboostd: prefetch end : app comstsltdstevenspin data_amount 48201728
2020-09-30 00:00:13.125 2472-9530/? E/pageboostd: active launch start : app comexampleStevensPin
2020-09-30 00:00:13.125 2472-9530/? E/pageboostd: comexampleStevensPin, amt 1536600 scnt 2 fcnt 0
2020-09-30 00:00:13.126 2472-9530/? E/pageboostd: comexampleStevensPin, amt 0 scnt 2 fcnt 0
2020-09-30 00:00:13.126 2472-9530/? E/pageboostd: active launch end : app comexampleStevensPin data_amount 1536600
2020-09-30 00:00:13.145 7174-7174/? E/mple.StevensPi: Not starting debugger since process cannot load the jdwp agent.
2020-09-30 00:00:13.481 572-572/? E/Layer: [Surface(name=AppWindowToken{8f83aa6 token=Token{a332c01 ActivityRecord{6c5ede8 u0 com.example.StevensPin/.MainActivity t2284}}})/@0xb5d144d - animation-leash#0] No local sync point found, barrierLayer : [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity$_1923#0]
2020-09-30 00:00:13.560 7174-7174/? A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 7174 (mple.StevensPin), pid 7174 (mple.StevensPin)
2020-09-30 00:00:13.580 1025-1121/? E/WindowManager: win=Window{96f549b u0 Splash Screen com.example.StevensPin EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true win.mViewVisibility=0 caller=com.android.server.wm.AppWindowToken.destroySurfaces:1248 com.android.server.wm.AppWindowToken.destroySurfaces:1229 com.android.server.wm.WindowState.onExitAnimationDone:5182 com.android.server.wm.WindowStateAnimator.onAnimationFinished:320 com.android.server.wm.WindowState.onAnimationFinished:5623 com.android.server.wm.-$$Lambda$yVRF8YoeNdTa8GR1wDStVsHu8xM.run:2 com.android.server.wm.SurfaceAnimator.lambda$getFinishedCallback$0$SurfaceAnimator:100 
2020-09-30 00:00:13.603 9594-9594/? A/DEBUG: pid: 7174, tid: 7174, name: mple.StevensPin  >>> com.example.StevensPin <<<
2020-09-30 00:00:13.604 9594-9594/? A/DEBUG:       #01 pc 00157a3f  /data/app/com.example.StevensPin-pGnjhn3RCPRS-R-mc79c5Q==/lib/arm/libflutter.so (BuildId: e975fb1af56ffc3c5acc61eaa8e0aba1720b5000)
2020-09-30 00:00:13.604 9594-9594/? A/DEBUG:       #02 pc 004e1a38  /data/app/com.example.StevensPin-pGnjhn3RCPRS-R-mc79c5Q==/lib/arm/libflutter.so!libflutter.so (offset 0x4e0000) (BuildId: e975fb1af56ffc3c5acc61eaa8e0aba1720b5000)
2020-09-30 00:00:14.003 507-507/? E/audit: type=1701 audit(1601420414.001:20595): auid=4294967295 uid=10309 gid=10309 ses=4294967295 subj=u:r:untrusted_app_27:s0:c53,c257,c512,c768 pid=7174 comm="mple.StevensPin" exe="/system/bin/app_process32" sig=6 res=1
2020-09-30 00:00:14.090 1025-1308/? E/InputDispatcher: channel 'f4478b2 com.example.StevensPin/com.example.StevensPin.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2020-09-30 00:00:14.094 1025-1433/? E/WindowManager: win=Window{f4478b2 u0 com.example.StevensPin/com.example.StevensPin.MainActivity EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true win.mViewVisibility=0 caller=com.android.server.wm.AppWindowToken.destroySurfaces:1248 com.android.server.wm.AppWindowToken.destroySurfaces:1229 com.android.server.wm.WindowState.onExitAnimationDone:5182 com.android.server.wm.-$$Lambda$01bPtngJg5AqEoOWfW3rWfV7MH4.accept:2 java.util.ArrayList.forEach:1262 com.android.server.wm.AppWindowToken.onAnimationFinished:3931 com.android.server.wm.AppWindowToken.commitVisibility:913 
2020-09-30 00:00:14.525 2472-9613/? E/pageboostd: prefetch start : app comstsltdstevenspin
2020-09-30 00:00:14.526 507-507/? E/audit: type=1400 audit(1601420414.525:20596): avc:  denied  { search } for  pid=2472 comm="pageboostd" name="com.stsltd.stevenspin" dev="sda31" ino=1708995 scontext=u:r:pageboostd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SM-G975F_10_0020 audit_filtered
2020-09-30 00:00:14.528 2472-9613/? E/pageboostd: comstsltdstevenspin, amt 48201728 scnt 15 fcnt 35
2020-09-30 00:00:14.529 2472-9613/? E/pageboostd: prefetch end : app comstsltdstevenspin data_amount 48201728

更新 2

在网上搜索时,我发现如果您使用第三方库并尝试缩小构建,也会发生类似的问题。

我在开始时使用msal_mobile 来验证用户。如果我不缩小我的构建

flutter build apk --no-shrink

现在应用程序可以运行并且不会崩溃。

另一方面,如果我避免使用以下msal_mobile 初始化代码,并使用启用收缩的flutter build apk 构建apk,它使用R8 进行收缩,应用程序不会再次崩溃。

class _MyAppState extends State<MyApp> {
    MsalMobile msal;

    @override
    void initState() {
        super.initState();
        MsalMobile.create('assets/auth_config.json', "https://login.microsoftonline.com/Organizations").then((client) {
            setState(() {
                msal = client;
            });
        });
    }
}

当您使用导致此类问题的 lib 时,是否有一些不同的方法来缩小应用程序。

【问题讨论】:

  • 你能在启动应用程序时读取手机的logcat吗?不需要根。只需插入手机,即可从 AS 中查看控制台。

标签: android flutter installation msal


【解决方案1】:

我遇到了同样的错误,并将问题缩小到 msal_mobile 包,该包在调用特定于平台的功能时遇到问题(特别是 msal_mobile.dart 的第 39 行)。

根据我读到的here,似乎Android修改和混淆过程在重命名方法时有点过分热心,使得msal_mobile包中使用的方法通道认为他们正在尝试的方法调用不存在。

我发现适合我自己情况的唯一解决方案并不理想,因为它增加了我的应用程序的大小,但它让我的项目再次工作,所以我想我会分享。

在您的项目目录中,打开文件android/app/build.gradle 并将以下行添加到 buildTypes 的发布部分:

buildTypes {
    release {
        signingConfig signingConfigs.debug

        minifyEnabled false   // Add this line
        shrinkResources false // Add this line
        useProguard false     // Add this line
    }
}

我希望这会有所帮助!

【讨论】:

  • 嗨@amphibious,感谢您的关注。正如你提到的,我实际上通过调整构建类型选项解决了这个问题。发布答案here。现在我面临另一个我认为与 msal_mobile 相关的问题。 Afrer 混淆构建应用程序运行时不会崩溃,但会出现错误。 Here 是详细信息。再次感谢。
猜你喜欢
  • 2021-01-22
  • 2020-01-15
  • 2019-01-24
  • 2020-09-27
  • 2019-06-06
  • 2018-10-22
  • 2021-12-03
  • 1970-01-01
  • 2022-10-19
相关资源
最近更新 更多