Flutter构建apk失败。

3

我正在尝试生成我的应用的apk,但遇到了很多问题: flutter build apk。 我正在使用firebase,但是无法构建apk。 看起来找不到firebase,它说找不到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个回答

0

尝试将以下内容添加到您的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

我已经尝试过了,但是出现了以下错误。> 在类型为 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 的对象上找不到参数 [DefaultExternalModuleDependency{group='com.google.firebase', name='firebase-bom', version='26.1.0', configuration='default'}] 的 implementation() 方法。 - Arnau Bosch
@ArnauBoschTekla.io,你能给我展示一下你的pubspec.yaml文件吗? - Alan Chan
是的!我已经添加了 puspec.yaml 文件。 - Arnau Bosch
pubspec.yaml 已添加。 - Arnau Bosch
@ArnauBoschTekla.io 我已经编辑了我的答案,请查看,注意有两个build.gradle文件,请确保路径正确。 - Alan Chan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接