Flutter 构建 apk 失败
Posted
技术标签:
【中文标题】Flutter 构建 apk 失败【英文标题】:Flutter build apk fails 【发布时间】:2021-03-09 03:07:12 【问题描述】:我在尝试生成我的应用程序的 apk 时遇到很多问题:flutter build apk 我正在使用 firebase,但我无法构建 apk。似乎没有找到firebase t 说它找不到com.google.firebase:firebase-bom:25.3.1。
我已经能够构建应用程序包,但我需要生成 apk。
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
* What went wrong:
Execution failed for task ':generateReleaseRFile'.
> Could not resolve all files for configuration ':releaseRuntimeClasspath'.
> Could not find com.google.firebase:firebase-bom:25.3.1.
Searched in the following locations:
- https://storage.googleapis.com/download.flutter.io/com/google/firebase/firebase-bom/25.3.1/firebase-bom-25.3.1.pom
- https://storage.googleapis.com/download.flutter.io/com/google/firebase/firebase-bom/25.3.1/firebase-bom-25.3.1.jar
Required by:
project :
> Could not find com.google.firebase:firebase-core:.
Required by:
project :
> Could not find androidx.annotation:annotation:1.1.0.
Searched in the following locations:
- https://storage.googleapis.com/download.flutter.io/androidx/annotation/annotation/1.1.0/annotation-1.1.0.pom
- https://storage.googleapis.com/download.flutter.io/androidx/annotation/annotation/1.1.0/annotation-1.1.0.jar
Required by:
project :
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':javaPreCompileRelease'.
> Could not resolve all files for configuration ':releaseCompileClasspath'.
> Could not find com.google.firebase:firebase-bom:25.3.1.
Required by:
project :
> Could not find com.google.firebase:firebase-core:.
Required by:
project :
> Could not find androidx.annotation:annotation:1.1.0.
Required by:
project :
* 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 3s
The plugin firebase_core could not be built due to the issue above.
这是我的构建 gradle:
That's my build.gradle:
buildscript
ext.kotlin_version = '1.3.50'
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
allprojects
repositories
google()
jcenter()
rootProject.buildDir = '../build'
subprojects
project.buildDir = "$rootProject.buildDir/$project.name"
subprojects
project.evaluationDependsOn(':app')
task clean(type: Delete)
delete rootProject.buildDir
我被这个错误卡住了大约两天,我不知道如何解决它。
name: test_app
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In ios, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+7
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dio: 3.0.9
shared_preferences: ^0.5.12+1
rxdart: ^0.23.1
timeago: ^2.0.27
cached_network_image: ^2.2.0+1
flutter_chips_input: ^1.9.3
flutter_paginator: ^0.0.6
url_launcher: ^5.5.1
share: ^0.6.5
image_picker: ^0.6.7+7
firebase_messaging: ^7.0.0
provider: ^4.3.2+2
flutter_datetime_picker: ^1.4.0
clipboard_manager: ^0.0.1
webview_flutter: ^0.3.22+1
app_review: ^2.0.1
flutter_cache_manager: ^1.4.2
uni_links: ^0.4.0
pub_semver: ^1.4.4
package_info: ^0.4.3+2
in_app_update: ^1.1.14
launch_review: ^2.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: "^0.7.0"
flutter_icons:
android: true
ios: true
image_path: "assets/launcher/test.png"
image_path_ios: "assets/launcher/test1.png"
image_path_android: "assets/launcher/test2.png"
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- assets/img/
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
fonts:
- family: Poppins
fonts:
- asset: assets/fonts/Poppins-Regular.ttf
- family: PoppinsBold
fonts:
- asset: assets/fonts/Poppins-Bold.ttf
- family: PoppinsSemiBold
fonts:
- asset: assets/fonts/Poppins-SemiBold.ttf
- family: PoppinsExtraBold
fonts:
- asset: assets/fonts/Poppins-ExtraBold.ttf
【问题讨论】:
【参考方案1】:尝试将此添加到您的 build.gradle
文件 (android/app/build.gradle),而不是 (android/build.gradle)
implementation platform('com.google.firebase:firebase-bom:26.1.0')
到您的依赖项,例如:
android/app/build.gradle
...
dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.annotation:annotation:1.1.0"
implementation platform('com.google.firebase:firebase-bom:26.1.0')
...
android/build.gradle
dependencies
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.4'
将此添加到您的pubspec.yaml
:
dependencies:
firebase_core: ^0.5.2
【讨论】:
我试过了,我得到了这个错误。> Could not find method implementation() for arguments [DefaultExternalModuleDependencygroup='com.google.firebase', name='firebase-bom', version='26.1.0', configuration='default'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
@ArnauBoschTekla.io 你能告诉我你的 pubspec.yaml 文件吗?
是的!我已经添加了 puspec.yaml 文件
添加的 pubspec.yaml
@ArnauBoschTekla.io 我已经编辑了我的答案,检查一下,注意有2个build.gradle文件,确保路径正确。以上是关于Flutter 构建 apk 失败的主要内容,如果未能解决你的问题,请参考以下文章
构建flutter应用程序的APK时任务':sms:verifyReleaseResources'执行失败
Flutter APK build android 资源链接失败的震动包