我已经构建了一个简单的 Flutter SMS 报告系统,但我面临着将项目转换为 APK 文件格式的挑战。
我已尝试使用 CMD 提示将 Flutter 项目转换为 APK 文件,但我认为我的设置存在 Gradle 问题,因此无法转换文件。
我尝试过使用CMD方法:
flutter 构建 apk
flutter 构建 apk --release
但是在运行命令后,我收到一条错误消息:
Microsoft Windows \[Version 10.0.22631.4249\]
(c) Microsoft Corporation. All rights reserved.
F:\\CurrentSMSAPP\\electionresults_results_sms_collation_mobileapp\>flutter build apk
Building with sound null safety
/main.dart: Error: Error when reading '/main.dart': The system cannot find the file specified.
package:electionresults_results_sms_collation_mobileapp//main.dart: Error: No 'main' method found.
Try adding a method named 'main' to your program.
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
\* Where:
Script 'D:\\installed\\flutter\\packages\\flutter_tools\\gradle\\flutter.gradle' line: 1151
\* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
\\> Process 'command 'D:\\installed\\flutter\\bin\\flutter.bat'' finished with non-zero exit value 1
\* 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 36s
Running Gradle task 'assembleRelease'... 38.5s
Gradle task assembleRelease failed with exit code 1
F:\\CurrentSMSAPP\\electionresults_results_sms_collation_mobileapp\>
项目是否构建并运行成功?您似乎有构建错误。日志说找不到 main.dart。确保它位于project_directory/lib/main.dart中。
您还应该在 pubspec.yaml 文件所在的位置运行
flutter build apk
命令。
如果您所做的一切都正确但无法解决问题,请尝试运行
flutter clean
,然后再次构建。
对于最终版本,您可以使用以下命令生成APK或appbundle进行发布。
应用程序包:
flutter build appbundle --no-tree-shake-icons --target-platform android-arm,android-arm64,android-x64 --release
APK:
flutter build apk --no-tree-shake-icons --target-platform android-arm,android-arm64,android-x64 --release