Flutter app stuck at installing with white screen

Problem Background and Symptoms:

A while ago, I tried setting up the Flutter environment and had a brief experience with it. After a long break, I recently became interested again and wanted to see what changes Flutter has undergone.

  1. I followed the official tutorial to set up the Flutter environment and ran flutter doctor without any issues.
  2. I downloaded a demo app project and tried running it on iOS. After the compilation completed, the app was installed on the simulator, but it got stuck on a white screen.
  3. After killing the app, I manually opened it, and it worked fine.

Attempts and Solutions:

  1. I tried installing it on an Android emulator, but encountered the same issue ❌.
  2. I attempted to run flutter clean to clear the cache, but the problem persisted ❌.
  3. I tried running flutter pub cache clean to clear the dependency cache, but the problem remained ❌.
  4. Running flutter run -v to view the output, I noticed that it got stuck at the line Connecting to service protocol:http://127.0.0.1:57071/0dqLN-ZPpFk=/. I suspected an issue with port 57071, so I ran lsof -i:57071 to check the process ID occupying that port and then killed the process using kill <pid>. However, the issue persisted, and I realized that the service changed ports every time, so the problem wasn’t related to that ❌.
  5. Suddenly, I noticed that every time I ran a Flutter command, the first line was Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!. I remembered that I had changed the source due to a poor network environment in the past. Could it be an issue with this source? I quickly checked the ~/.zshrc file and found the following configuration:
    1
    2
    3
    export PUB_HOSTED_URL=https://pub.flutter-io.cn
    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
    export FLUTTER_GIT_URL=https://gitee.com/mirrors/Flutter.g
    I deleted these lines, restarted VSCode, and ran the command again. The problem was resolved. In retrospect, it seems that the content of this source was outdated or incorrect! ✅

In summary, one should not easily trust third-party sources. Configuring the network environment correctly is always the first step in setting up the environment.

After searching on Stack Overflow for a while, I couldn’t find any answers pointing to the source. I’m documenting this experience here, hoping it can help others facing the same issue. ♥️

If the above solution doesn’t resolve your problem, you can refer to:

https://stackoverflow.com/questions/75665760/flutter-run-stuck-on-launching

https://stackoverflow.com/questions/68698437/flutter-app-stuck-at-installing-with-white-screen

flutter运行后白屏卡住无法启动 / Flutter app stuck at installing with white screen

问题背景和症状:

很久之前尝试配置过一次flutter环境,体验了一下。很久没用了,最近有了兴趣,又想看下flutter有什么变化。

  1. 按照官方教程装好了flutter环境,运行flutter doctor无异常项
  2. 下载了一个demo app工程,点击运行(ios),编译完成后,安装到了模拟器上,app自动打开了,但是卡在白屏。
  3. 杀死app后,手动打开能正常进入。

尝试和解决

  1. 尝试安装到android模拟器上,也是同样的症状❌
  2. 尝试运行flutter clean清除缓存,问题没有解决❌
  3. 尝试运行flutter pub cache clean清除依赖缓存,问题没有解决❌
  4. 运行flutter run -v查看输出信息,发现最后是卡在Connecting to service protocol:http://127.0.0.1:57071/0dqLN-ZPpFk=/这一行了,怀疑是57071这个端口有问题,运行lsof -i:57071查看占用这个端口的进程的pid,然后运行kill <pid>杀掉这个进程。再次运行发现还是不行,并且发现这个service每次都会换个端口,问题应该不是在这。❌
  5. 忽然留意到每次运行flutter命令的时候,第一句都是Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!,想起来以前因为网络环境不好,换过源,不会是这个源有问题吧,于是赶紧查看~/.zshrc文件,果然在里面发现了这个配置
    1
    2
    3
    export PUB_HOSTED_URL=https://pub.flutter-io.cn
    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
    export FLUTTER_GIT_URL=https://gitee.com/mirrors/Flutter.g
    删掉这几行,然后重启vscode,再次运行,问题就解决了。回顾一下应该就是这个源的内容不够新甚至不正确导致的!✅

总结,不能轻易相信第三方源,配置好网络环境永远是配置环境的第一步

stackoverflow上查了半天,没有一个将问题指向源的,在此做下记录,希望能帮助到遇到同样问题的人。♥️

如果上面没有解决你的问题,可以参考:

https://stackoverflow.com/questions/75665760/flutter-run-stuck-on-launching

https://stackoverflow.com/questions/68698437/flutter-app-stuck-at-installing-with-white-screen

记一次overloadaggressively造成的崩溃

将Kotlin版本从1.1.2-4升级到1.3.11后,发现打的release包开机就会崩溃:崩溃日志为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
java.lang.RuntimeException: Unable to instantiate application com.tencent.sigma.patch.HotPatchApplication: java.lang.ClassNotFoundException: Didn't find class "com.tencent.sigma.patch.HotPatchApplication" on path: DexPathList[[zip file "/data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/base.apk"],nativeLibraryDirectories=[/data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/lib/arm, /data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/base.apk!/lib/armeabi, /system/lib, /vendor/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:993)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5801)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1683)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:173)
at android.app.ActivityThread.main(ActivityThread.java:6650)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.tencent.sigma.patch.HotPatchApplication" on path: DexPathList[[zip file "/data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/base.apk"],nativeLibraryDirectories=[/data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/lib/arm, /data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/base.apk!/lib/armeabi, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newApplication(Instrumentation.java:1088)
at android.app.LoadedApk.makeApplication(LoadedApk.java:987)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5801) 
at android.app.ActivityThread.-wrap1(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1683) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:173) 
at android.app.ActivityThread.main(ActivityThread.java:6650) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:818) 
Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/base.apk because: Failure to verify dex file '/data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/base.apk': Out-of-order annotation_element name_idx: 7150 then 7150
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:353)
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.<init>(DexFile.java:74)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
at dalvik.system.DexPathList.<init>(DexPathList.java:157)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:35)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:695)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:729)
at android.app.LoadedApk.getResources(LoadedApk.java:956)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2282)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5723)
... 8 more

乍一看,以为是HotPatchApplication被混淆的原因导致Class Not Found,于是尝试keep住HotPatchApplication这个类,但是发现问题依旧。于是又怀疑是前不久升级gradle对分包造成了影响,对apk中的dex文件进行分析,发现HotPatchApplication这个类稳稳的躺在第一个dex文件中。

后来又进行了以下的尝试:

​ 1.尝试按顺序更改Kotlin版本,最后,当Kotlin版本为1.3.0时,发现问题出现了。

​ 2.另一个线索是当我打开Proguard时,那就是minifyEnable true,崩溃就出现了。

经过以上排查,基本确定了问题出在Kotlin和混淆的身上。最后发现上述日志中有一行:

1
Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/base.apk because: Failure to verify dex file '/data/app/com.tencent.dreamreader-P2-qUIVdDrdEOhONvRwOtw==/base.apk': Out-of-order annotation_element name_idx: 7150 then 7150

这个报错是第一次见到,上网搜了下,最终定位在混淆时的一个参数身上:-overloadaggressively

ProGuard官网解释:

-overloadaggressively Specifies to apply aggressive overloading while obfuscating. Multiple fields and methods can then get the same names, as long as their arguments and return types are different, as required by Java bytecode (not just their arguments, as required by the Java language). This option can make the processed code even smaller (and less comprehensible). Only applicable when obfuscating.

可以看出,开启该选项可能把不同的方法或者变量混淆成相同的名字,这样会尽可能的减小代码体积。但是由于过于激进,造成了dex文件中有重复annotation_element,这个问题在编译和打包时并不会报错,只有在开启软件时才会发现。

至于为什么升级了Kotlin才有这个问题,猜测原因是新版本的kotlin中加入了Keep注释与Java的Keep注释同名造成的。

解决办法:

去掉混淆文件(proguard.txt)中的-overloadaggressively

参考:

https://stackoverflow.com/questions/56458360/app-crashed-when-r8-enabled-with-existing-proguard-settings

https://issuetracker.google.com/issues/129241209#comment11

https://stackoverflow.com/questions/51948250/failure-to-verify-dex-file-out-of-order-annotation-element-name-idx

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×