简体   繁体   English

Flutter 构建 apk 失败

[英]Flutter build apk fails

I am having lots of problems trying to generate the apk of my App: flutter build apk I am using firebase, but I am not able to build the apk.我在尝试生成我的应用程序的 apk 时遇到很多问题:flutter build apk 我正在使用 firebase,但我无法构建 apk。 It seems that doesn't find the firebase t says that it can't find the com.google.firebase:firebase-bom:25.3.1.似乎没有找到 firebase t 说它找不到 com.google.firebase:firebase-bom:25.3。

I have been able to build the app bundle but I need to generate the apk.我已经能够构建应用程序包,但我需要生成 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.

That's my build gradle:那是我的构建 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
}

I have been stuck about two days for that error, I don't know how to solve it.我被这个错误卡住了大约两天,我不知道如何解决它。

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

Try adding this to your build.gradle file (android/app/build.gradle), not (android/build.gradle)尝试将此添加到您的build.gradle文件(android/app/build.gradle),而不是(android/build.gradle)

implementation platform('com.google.firebase:firebase-bom:26.1.0')

to your dependencies such as:到您的依赖项,例如:

android/app/build.gradle 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安卓/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'
    }

Also add this to your pubspec.yaml :还要将此添加到您的pubspec.yaml

dependencies:
  firebase_core: ^0.5.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM