Flutter 和 Firebase:任务 ':firebase_auth:compileDebugJavaWithJavac' 执行失败 [英] Flutter and Firebase: Execution failed for task ':firebase_auth:compileDebugJavaWithJavac'

查看:26
本文介绍了Flutter 和 Firebase:任务 ':firebase_auth:compileDebugJavaWithJavac' 执行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建我的 Flutter 应用程序以与 firebase 交互.我已将 google-services.json 放在正确的位置.但是,每当我尝试构建 Android 应用程序时,我都会收到以下运行日志:

I am trying to build my flutter application to interact with firebase. I have placed my google-services.json in the right place. However whenever i try to build the Android application i get the following run log:

Running "flutter packages get" in smart_diet_flutter...          2.6s
Launching libmain.dart on ONEPLUS A6003 in debug mode...
Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:9: error: cannot find symbol
import androidx.annotation.NonNull;
                          ^
  symbol:   class NonNull
  location: package androidx.annotation
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:10: error: cannot find symbol
import androidx.annotation.Nullable;
                          ^
  symbol:   class Nullable
  location: package androidx.annotation
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:638: error: cannot find symbol
  private void reportException(Result result, @Nullable Exception exception) {
                                               ^
  symbol:   class Nullable
  location: class FirebaseAuthPlugin
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:550: error: cannot find symbol
    public void onComplete(@NonNull Task<AuthResult> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.SignInCompleteListener
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:569: error: cannot find symbol
    public void onComplete(@NonNull Task<Void> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.TaskVoidCompleteListener
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:587: error: cannot find symbol
    public void onComplete(@NonNull Task<SignInMethodQueryResult> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.GetSignInMethodsCompleteListener
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:186: error: cannot find symbol
                      public void onComplete(@NonNull Task<AuthResult> task) {
                                              ^
  symbol: class NonNull
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:445: error: cannot find symbol
              public void onComplete(@NonNull Task<GetTokenResult> task) {
                                      ^
  symbol: class NonNull
C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:499: error: cannot find symbol
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                                          ^
  symbol: class NonNull
Note: C:flutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.8.0androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
9 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':firebase_auth:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* 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 22s
Finished with error: Gradle task assembleDebug failed with exit code 1

根据我的研究,我发现我可能需要升级到 AndroidX.我按照这个 link 来升级我的 android.但是,在尝试构建和运行应用程序时,我仍然遇到相同的错误.

From my research I found that i might need to upgrade to AndroidX. I followed this link to upgrade my android. However i still got the same errors when trying to build and run the app.

我使用 InteliJ 作为我的 IDE 和 flutter 项目,我的 pubspec.yaml 如下:

I am using InteliJ as my IDE with a flutter project and my pubspec.yaml is as follows:

name: smart_diet_flutter
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.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.0.0-dev.68.0 <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: ^0.1.2
  firebase_auth: 0.8.0
  firebase_database: 1.1.0+1

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/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

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/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.io/custom-fonts/#from-packages

assets:
  - assets/flutter-icon.png

推荐答案

您要么需要迁移到 AndroidX,要么需要降级到与 AndroidX 之前版本兼容的插件版本.

You either need to migrate to AndroidX or downgrade to the plugin versions that are compatible with pre-AndroidX.

关注https://github.com/flutter/flutter/issues/27106 关于与迁移相关的问题(另见 https://github.com/flutter/flutter/问题/27146https://github.com/flutter/flutter/issues/27128 对于与您的问题相同的错误输出)

Follow https://github.com/flutter/flutter/issues/27106 about issues related to the migration (see also https://github.com/flutter/flutter/issues/27146, https://github.com/flutter/flutter/issues/27128 for the same error output as in your question)

另见

重大变化.从已弃用的原始 Android 支持库迁移到 AndroidX.这不应导致任何功能更改,但它需要任何使用此插件的 Android 应用程序也进行迁移 如果他们使用的是原始支持库.

Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

这篇关于Flutter 和 Firebase:任务 ':firebase_auth:compileDebugJavaWithJavac' 执行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆