You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Flutter构建Release版APK时出现多类警告与编译错误求助

Flutter构建Release版APK时出现多类警告与编译错误求助

各位大佬好!我最近几天一直在折腾Flutter构建Release APK的问题,试了清理缓存、重新拉取依赖这些常规操作,还是没搞定,现在把遇到的警告和编译错误整理出来,求帮忙看看怎么解决!

问题详情

执行flutter build apkflutter build apk --release时,先弹出一堆警告,最后直接编译失败,具体内容如下:

1. Android Gradle Plugin(AGP)版本警告

Warning: Flutter support for your project's Android Gradle Plugin version (Android Gradle Plugin version 8.2.1) will soon be dropped. Please upgrade your Android Gradle Plugin version to a version of at least Android Gradle Plugin version 8.6.0 soon. Alternatively, use the flag "--android-skip-build-dependency-validation" to bypass this check.
Potential fix: Your project's AGP version is typically defined in the plugins block of the settings.gradle file (/Users/rajpurohittanu/Documents/GitHub/vezigo-flutter/android/settings.gradle), by a plugin with the id of com.android.application. If you don't see a plugins block, your project was likely created with an older template version. In this case it is most likely defined in the top-level build.gradle file (/Users/rajpurohittanu/Documents/GitHub/vezigo-flutter/android/build.gradle) by the following line in the dependencies block of the buildscript: "classpath 'com.android.tools.build:gradle:'".

2. SDK XML版本警告

Warning: SDK processing. This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.

3. 字体Tree-Shaking提示

Font asset "CupertinoIcons.ttf" was tree-shaken, reducing it from 257628 to 988 bytes (99.6% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 5156 bytes (99.7% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.

4. 核心编译错误(导致构建失败)

e: org.jetbrains.kotlin.util.FileAnalysisException: While analysing /Users/rajpurohittanu/.pub-cache/hosted/pub.dev/device_info_plus-12.1.0/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt:15:5: java.lang.IllegalArgumentException: source must not be null
at org.jetbrains.kotlin.util.AnalysisExceptionsKt.wrapIntoFileAnalysisExceptionIfNeeded(AnalysisExceptions.kt:57)
at org.jetbrains.kotlin.fir.FirCliExceptionHandler.handleExceptionOnFileAnalysis(Utils.kt:249)
at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runCheckers(analyse.kt:46)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.resolveAndCheckFir(firUtils.kt:77)
at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.buildResolveAndCheckFirViaLightTree(firUtils.kt:88)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModuleToAnalyzedFir(jvmCompilerPipeline.kt:319)
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.compileModulesUsingFrontendIrAndLightTree(jvmCompilerPipeline.kt:118)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:148)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:43)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:103)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:49)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:464)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:73)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:506)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:423)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:301)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:129)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:675)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1660)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.hand...

我尝试过的操作(没解决问题)

  • 执行flutter clean./gradlew clean清理缓存
  • 重新拉取依赖:flutter pub get
  • 重启Android Studio和终端

求大佬们给的具体解决方案

针对每个问题,希望能有可落地的操作步骤:

1. AGP版本升级相关

按照提示需要升级到8.6.0+,但担心和当前Flutter版本不兼容(我的Flutter版本是[补充你的Flutter版本号]),有没有稳妥的升级步骤?或者暂时用跳过检查的 flag 会不会有后续风险?

2. SDK XML版本警告

这个是不是只要同步Android Studio和命令行工具的版本就行?具体怎么检查和更新这两个工具的版本?

3. 字体Tree-Shaking提示

这个应该是优化提示不影响构建,但如果想保留完整字体,是不是直接加参数构建就可以?比如flutter build apk --release --no-tree-shake-icons

4. device_info_plus编译错误

这个错误看起来是插件的Kotlin代码分析出问题了,有没有遇到过类似情况的?是不是插件版本(我用的是12.1.0)和AGP/Kotlin版本不兼容?需要降级或升级插件吗?或者有没有其他办法修复这个source must not be null的错误?

麻烦各位大佬指点一下,实在卡了好几天了,谢谢大家!

火山引擎 最新活动