Flutter 和 Firebase:任务 ':firebase_auth:compileDebugJavaWithJavac' 执行失败
Posted
技术标签:
【中文标题】Flutter 和 Firebase:任务 \':firebase_auth:compileDebugJavaWithJavac\' 执行失败【英文标题】:Flutter and Firebase: Execution failed for task ':firebase_auth:compileDebugJavaWithJavac'Flutter 和 Firebase:任务 ':firebase_auth:compileDebugJavaWithJavac' 执行失败 【发布时间】:2019-07-01 14:56:46 【问题描述】:我正在尝试构建我的颤振应用程序以与 firebase 交互。我已将我的 google-services.json 放在正确的位置。但是,每当我尝试构建 android 应用程序时,我都会得到以下运行日志:
Running "flutter packages get" in smart_diet_flutter... 2.6s
Launching lib\main.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-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:9: error: cannot find symbol
import androidx.annotation.NonNull;
^
symbol: class NonNull
location: package androidx.annotation
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:10: error: cannot find symbol
import androidx.annotation.Nullable;
^
symbol: class Nullable
location: package androidx.annotation
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:638: error: cannot find symbol
private void reportException(Result result, @Nullable Exception exception)
^
symbol: class Nullable
location: class FirebaseAuthPlugin
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:550: error: cannot find symbol
public void onComplete(@NonNull Task<AuthResult> task)
^
symbol: class NonNull
location: class FirebaseAuthPlugin.SignInCompleteListener
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:569: error: cannot find symbol
public void onComplete(@NonNull Task<Void> task)
^
symbol: class NonNull
location: class FirebaseAuthPlugin.TaskVoidCompleteListener
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:587: error: cannot find symbol
public void onComplete(@NonNull Task<SignInMethodQueryResult> task)
^
symbol: class NonNull
location: class FirebaseAuthPlugin.GetSignInMethodsCompleteListener
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:186: error: cannot find symbol
public void onComplete(@NonNull Task<AuthResult> task)
^
symbol: class NonNull
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:445: error: cannot find symbol
public void onComplete(@NonNull Task<GetTokenResult> task)
^
symbol: class NonNull
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:499: error: cannot find symbol
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth)
^
symbol: class NonNull
Note: C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.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 升级了我的安卓。但是,在尝试构建和运行应用程序时,我仍然遇到相同的错误。
我在 Flutter 项目中使用 InteliJ 作为我的 IDE,我的 pubspec.yaml 如下:
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
【问题讨论】:
【参考方案1】:你需要在你的文件graddle.properties
中添加这行
android.useAndroidX=true
android.enableJetifier=true
【讨论】:
去哪里?在哪个部分?两者中哪个 gradle 文件? @PeakGen 只有一个 graddle.properties 文件 @PeakGen yourapp/android/gradle.properties 我有同样的错误并且已经有了这些行。不醒【参考方案2】:检查您的 gradle plugin
是否与您的 gradle version
兼容。
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
当我的 gradle 版本是 6.6.1
而我的插件是 4.0.2
时,我遇到了同样的错误。将插件更新为4.1.0
为我解决了这个问题。
gradle plugin
版本位于 android/build.gradle
上,作为依赖项上的 classpath 'com.android.tools.build:gradle:your version'
。
gradle version
位于android/gradle/wrapper/gradle-wrapper.properties
下的distributionUrl
。
希望它能帮助其他人。
【讨论】:
【参考方案3】:您需要迁移到 AndroidX 或降级到与 pre-AndroidX 兼容的插件版本。
关注https://github.com/flutter/flutter/issues/27106,了解与迁移相关的问题(另请参阅https://github.com/flutter/flutter/issues/27146、https://github.com/flutter/flutter/issues/27128,了解与您的问题相同的错误输出)
另见
重大变化。从已弃用的原始 Android 支持库迁移到 AndroidX。这不应导致任何功能更改,但如果使用原始支持库,则需要使用此插件的任何 Android 应用 also migrate。
【讨论】:
那行得通。没有运行 flutter clean 感谢您的帮助【参考方案4】:我在更新到 Flutter Channel beta 1.19.0-4.3.pre 后就开始面临这个问题
对我来说,使用 AndroidX 并没有帮助(我已经在使用 AndroidX)
我不得不升级版本
firebase_auth to 0.16.1 from 0.15.3
firebase_messaging to 6.0.16 from 6.0.15
仅供参考,以下是我的环境:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.19.0-4.3.pre, on Mac OS X 10.15.5 19F101, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
[✓] Android Studio (version 4.0)
[✓] Connected device (1 available)
• No issues found!
【讨论】:
【参考方案5】:在遵循 Android X 迁移指南后,最适合我的解决方案是 CLEAN CACHE
在下方输入命令
--> flutter packages pub cache clean
【讨论】:
以上是关于Flutter 和 Firebase:任务 ':firebase_auth:compileDebugJavaWithJavac' 执行失败的主要内容,如果未能解决你的问题,请参考以下文章
Flutter Firebase 错误(任务 ':app:mergeExtDexDebug' 执行失败)
Flutter 上的 Firebase 错误:无法解析配置“:firebase_core:debugCompileClasspath”的所有任务依赖项
Flutter Firebase 错误(2020)-(任务“:app:mergeDexDebug”执行失败)