Flutter Notes | 记录基于 macOS 上使用 Flutter 过程中遇到的一些问题

点滴积累,跟随鸡老大~

前言

每当接触一个新东西,总是会遇到一些想喷人的问题,虽然在后期回过头想想,好简单,当初怎么就掉坑出不来了呢?

正好公司最近来个新项目,从 Flutter 出来到现在一直处于偷窥状态,恰好逢此机会,Flutter 搞起来~

记录自己 Flutter 使用过程遇到的一些问题,希望可以帮助和我一样刚入坑的小伙伴~

慢慢积累吧~

问题收集

积少成多,一起变得更好~

1. Waiting for another flutter command to release the startup lock...

iTerm 中键入如下内容:

killall -9 dart

2. Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve io.flutter:flutter_embedding_debug:1.0.0-540786dd51f112885a89792d678296b95e6622e5.
     Required by:
         project :app
      > Skipped due to earlier error
      > Skipped due to earlier error
      > Skipped due to earlier error
   > Could not resolve io.flutter:arm64_v8a_debug:1.0.0-540786dd51f112885a89792d678296b95e6622e5.
     Required by:
         project :app
      > Skipped due to earlier error
      > Skipped due to earlier error
      > Skipped due to earlier error
   > Could not resolve io.flutter:x86_debug:1.0.0-540786dd51f112885a89792d678296b95e6622e5.
     Required by:
         project :app
      > Skipped due to earlier error
      > Skipped due to earlier error
      > Skipped due to earlier error
   > Could not resolve io.flutter:x86_64_debug:1.0.0-540786dd51f112885a89792d678296b95e6622e5.
     Required by:
         project :app
      > Skipped due to earlier error
      > Skipped due to earlier error
      > Skipped due to earlier error

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 9s
Exception: Gradle task assembleDebug failed with exit code 1

掘友很贴心的指点我是因为依赖没有下载下来导致的

下面提供三种方式,多多尝试:

  • 将 VPN 设置为全局代理模式;
  • 替换 Android 依赖源为阿里云,感谢 逝水流光
maven { url 'https://maven.aliyun.com/repository/googlemaven.aliyun.com/repository/goo...' }
maven { url 'https://maven.aliyun.com/repository/jcentermaven.aliyun.com/repository/jce...' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/publicmaven.aliyun.com/nexus/content/...' }

3. If you're running an application and need to access the binary messenger before runApp() has been called (for example, during plugin initialization), then you need to explicitly call the WidgetsFlutterBinding.ensureInitialized() first.

如日志提示一样,在 runApp() 前调用 WidgetsFlutterBinding.ensureInitialized()。

4. [!] Invalid Podfile file: [!] Specifying multiple post_install hooks is unsupported..

Podfile 只能有一个 post_install,所以合并到一个里面就好,我这纯粹野路子解决方案。

5. Error running 'splash.dart': Entrypoint doesn't contain a main function

检测 main.dart 目录地址是否正确。

image.png

6.AAPT: error: failed to read PNG signature: file does not start with PNG signature.

问题原因是对方提供我一张 jpg 的图片,我直接修改后缀为 png 了。

解决方法:在 app/build.gradle 中新增如下:

aaptOptions {cruncherEnabled = false }

作用就是通知 Android Studio 别检查我图片的有效性了。

7.Could not find the built application bundle at build/ios/iphoneos/Runner.app.

因为 Leader 修改了 iOS 名称,所以我在 Android Studio 中直接选择运行 iOS 始终不成功,因为它目标是将 Runner 运行目标设备上,但是实际却生成了 Leader 修改后的包名字,所以直接导致找不到 Runner。

修改方式:

  • 将 Display Name 修改为 Runner 即可,如下图:

image.png

8.The builder for route "/actionDetailPage?loadUrl=https://guokr.com" returned null.

这个问题吧,我也有点懵,先放一下错误日志:

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building Builder(dirty):
The builder for route "/actionDetailPage?loadUrl=https://guokr.com" returned null.

Route builders must never return null.
The relevant error-causing widget was: 
  MaterialApp file:///Users/heliquan/CodePro/FlutterPro/haozhuan_app/lib/main.dart:34:12
When the exception was thrown, this was the stack: 
#0      CupertinoPageRoute.buildPage. (package:flutter/src/cupertino/route.dart:260:9)
#1      CupertinoPageRoute.buildPage (package:flutter/src/cupertino/route.dart:266:6)
#2      _ModalScopeState.build. (package:flutter/src/widgets/routes.dart:804:43)
#3      Builder.build (package:flutter/src/widgets/basic.dart:6998:48)
#4      StatelessElement.build (package:flutter/src/widgets/framework.dart:4576:28)
...

这个问题我也比较懵逼,跳转传递值,很 easy 的东西,而且我传递的是一个地址链接,又不是含有中文的东西。

But,死活不行,网上各种搜。

最后,想着要不然转义下吧。结果,好了。

NavigatorUtil.jumpFormRight(context,
                    '${Routes.actionDetailPage}?loadUrl=${Uri.encodeComponent(mActionList[index].url)}');

难道传递 URL 都不能直接传?

回头哪儿天试试。

9. uses-sdk:minSdkVersion 17 cannot be smaller than version 19 declared in library(2020-07-12)

日志如下:

/Users/HLQ/CodePro/FlutterPro/xxx_app/android/app/src/profile/AndroidManifest.xml Error:
        uses-sdk:minSdkVersion 17 cannot be smaller than version 19 declared in library [com.mob.push.plugins:oppo:2.1.0] /Users/HLQ/.gradle/caches/transforms-2/files-2.1/91fa5aa891331ae54500dada38fa5849/oppo-2.1.0/AndroidManifest.xml as the library might be using APIs not available in 17
        Suggestion: use a compatible library with a minSdk of at most 17,
                or increase this project's minSdk version to at least 19,
                or use tools:overrideLibrary="com.heytap.mcssdk" to force usage (may lead to runtime failures)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processProfileManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 17 cannot be smaller than version 19 declared in library [com.mob.push.plugins:oppo:2.1.0] /Users/HLQ/.gradle/caches/transforms-2/files-2.1/91fa5aa891331ae54500dada38fa5849/oppo-2.1.0/AndroidManifest.xml as the library might be using APIs not available in 17
        Suggestion: use a compatible library with a minSdk of at most 17,
                or increase this project's minSdk version to at least 19,
                or use tools:overrideLibrary="com.heytap.mcssdk" to force usage (may lead to runtime failures)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

我得解决方案是:

  • 修改 build 文件中的 minSdk 改为 19,最后同步即可

11. GC overhead limit exceeded(2020-07-13)

日志如下:

[+44802 ms] FAILURE: Build failed with an exception.
[   +4 ms] * What went wrong:
[        ] Failed to notify build listener.
[        ] > GC overhead limit exceeded
[        ] * Try:
[        ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[        ] * Get more help at https://help.gradle.org
[        ] BUILD FAILED in 1m 1s

修改方案如下:

gradle.properties:

  • org.gradle.jvmargs=-Xmx4096M

app build 中添加:

dexOptions {
    javaMaxHeapSize "4g"
}

Thanks

你可能感兴趣的:(flutter)