我通常可以构建调试apk,但是当我尝试构建发行版或配置文件apk时,出现以下错误:
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 896
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command 'C:\src\flutter\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 1m 1s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 62.3s
Gradle task assembleRelease failed with exit code 1
这是flutter.gradle中的第896行:project.exec {
logging.captureStandardError LogLevel.ERROR
executable flutterExecutable.absolutePath
workingDir sourceDir
if (localEngine != null) {
args "--local-engine", localEngine
args "--local-engine-src-path", localEngineSrcPath
}
if (verbose) {
args "--verbose"
} else {
args "--quiet"
}
args "assemble"
args "--depfile", "${intermediateDir}/flutter_build.d"
args "--output", "${intermediateDir}"
if (performanceMeasurementFile != null) {
args "--performance-measurement-file=${performanceMeasurementFile}"
}
if (!fastStart || buildMode != "debug") {
args "-dTargetFile=${targetPath}"
} else {
args "-dTargetFile=${Paths.get(flutterRoot.absolutePath, "examples", "splash", "lib", "main.dart")}"
}
args "-dTargetPlatform=android"
args "-dBuildMode=${buildMode}"
if (trackWidgetCreation != null) {
args "-dTrackWidgetCreation=${trackWidgetCreation}"
}
if (splitDebugInfo != null) {
args "-dSplitDebugInfo=${splitDebugInfo}"
}
if (treeShakeIcons == true) {
args "-dTreeShakeIcons=true"
}
if (dartObfuscation == true) {
args "-dDartObfuscation=true"
}
if (dartDefines != null) {
args "--DartDefines=${dartDefines}"
}
if (bundleSkSLPath != null) {
args "-iBundleSkSLPath=${bundleSkSLPath}"
}
if (extraGenSnapshotOptions != null) {
args "--ExtraGenSnapshotOptions=${extraGenSnapshotOptions}"
}
if (extraFrontEndOptions != null) {
args "--ExtraFrontEndOptions=${extraFrontEndOptions}"
}
args ruleNames
}
我在安装了相同Flutter包的同一台笔记本电脑上构建了没有任何问题的其他应用程序。我已经读过 Pubspec.yaml 上的软件包可能是原因,所以我做了以下事情:
1-我试图在pubspec.yaml上删除我的软件包并重建该应用程序,但它没有起作用。
2-我将相同的程序包添加到另一个应用程序中并进行了构建,并且构建正常。
因此,看来这不是原因。
这是我的Pubspec.yaml:
version: 1.0.0+1
environment:
sdk: ">=2.5.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.0
sqflite: ^1.1.7+1
path: ^1.6.4
path_provider: ^1.4.0
provider: ^3.1.0+1
http: ^0.12.2
connectivity: ^0.4.9+2
carousel_slider: ^2.2.1
share: ^0.6.5
# admob_flutter: ^0.3.4
url_launcher: ^5.5.3
photo_view: ^0.9.2
firebase_core: ^0.5.0
# firebase_messaging: ^6.0.12
firebase_auth: ^0.18.0+1
# cloud_firestore: ^0.14.0+2
# firebase_dynamic_links: ^0.5.0+11
# firebase_analytics: ^5.0.16
google_sign_in: ^4.5.3
# rxdart: ^0.24.1
cached_network_image: ^2.3.1
# in_app_purchase: ^0.3.4+5
# firebase_mlkit_language: ^1.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
fonts:
- family: Sons
fonts:
- asset: assets/fonts/Sons.ttf
- asset: assets/fonts/sons_of_sons.ttf
uses-material-design: true
assets:
- assets/varty.sqlite
- assets/images/photo.jpg
最佳答案
埃文(Evan)的评论很好地解决了问题:
This is a shot in the dark but do you use custom icons for fonts? I noticed you have two font files. If yes, try running the release apk command with --no-tree-shake-icons, I recently had an error like this with the same line number 896. Also, when you run the debug version, does the console say something like "this application cannot tree shake icons fonts. "?
只需记住要构建调试apk,然后使用相同的命令进行概要分析并最终发布一个。
关于flutter - 无法建立Flutter APK以发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63850928/