简体   繁体   English

Flutter 应用程序在使用 release apk 启动时崩溃,但使用“flutter run”运行良好

[英]Flutter app crash on startup with release apk, but runs fine with 'flutter run'

New to flutter/mobile development.颤振/移动开发的新手。 Had to do a bit of R&D to get what i need in a mobile app, I'm stuck at the very end of the finish line.不得不做一些研发才能在移动应用程序中获得我需要的东西,我被困在终点线的尽头。 ie making my .apk work on the actual device.即让我的 .apk 在实际设备上工作。

I've tried installing app with flutter install and by transferting build\\app\\outputs\\apk\\release\\app-arm64-v8a-release.apk on to my device.我尝试使用flutter install安装应用程序,并将build\\app\\outputs\\apk\\release\\app-arm64-v8a-release.apk传输到我的设备上。 App get installed successfully, but crashes immediately on the start.应用程序安装成功,但在开始时立即崩溃。

On the other hand It builds and runs fine with flutter run , on both emulator and on physical device (s10+)另一方面,它在模拟器和物理设备 (s10+) 上使用flutter run构建并运行良好

Build建造

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).

No plan to publish it on the Play Store, it has to be used internally and i'm stuck at the very end of my work.没有计划在 Play 商店上发布它,它必须在内部使用,我被困在我工作的最后。 Any word of advice what to look for to solve this?有什么建议可以解决这个问题吗?

Update更新

Logcat set to Error 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

Update 2更新 2

While searching online i've found that similar issue happened if you are using a third party lib and try shrinking the build.在网上搜索时,我发现如果您使用第三方库并尝试缩小构建,则会发生类似的问题。

I'm using msal_mobile for authenticating user at the beginning.我在开始时使用msal_mobile对用户进行身份验证。 If i don't shrink my build如果我不缩小我的构建

flutter build apk --no-shrink

Now the app works and doesn't crash.现在该应用程序可以运行并且不会崩溃。

On the other hand if I avoid the following msal_mobile initializing code, and build the apk with shrinking enabled flutter build apk , which uses R8 to shrink, app doesn't crash again.另一方面,如果我避免使用以下msal_mobile初始化代码,并使用启用收缩的flutter build apkflutter build 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;
            });
        });
    }
}

Is there some different approach to shrink the app when u are using lib that causes such issue.当您使用导致此类问题的 lib 时,是否有一些不同的方法来缩小应用程序。

I encountered the same error and narrowed the problem down to the msal_mobile package having issues invoking platform-specific functionality with its method channels (specifically Line 39 of msal_mobile.dart ).我遇到了同样的错误,并将问题缩小到msal_mobile包,该包在使用其方法通道(特别是msal_mobile.dart第 39 msal_mobile.dart )调用特定于平台的功能时出现问题。

Based on what I read here , it seems like the Android modification and obfuscation process ends up being a bit overzealous when renaming methods, making the method channels used in the msal_mobile package think that the method they are trying to call doesn't exist.根据我在此处阅读的内容,在重命名方法时,Android 修改和混淆过程似乎有点过分msal_mobile ,使得msal_mobile包中使用的方法通道认为他们试图调用的方法不存在。

The only solution that I found to work for my own situation isn't ideal, as it increases the size of my app, but it got my project working again, so I thought I would share.我发现适用于我自己情况的唯一解决方案并不理想,因为它增加了我的应用程序的大小,但它让我的项目再次运行,所以我想我会分享。

In your project's directory, open the file android/app/build.gradle and add the following lines to the release section of buildTypes:在您的项目目录中,打开文件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
    }
}

I hope this helps a bit!我希望这个能有一点帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM