简体   繁体   English

当我尝试在我的 flutter 应用程序中使用 firebase_Auth 时出现问题

[英]Problem occurs when i'm trying to use firebase_Auth in my flutter app

i'm new to flutter and wants to integrate my app with firebase.我是 flutter 的新手,想将我的应用程序与 firebase 集成。 I copy the code from this site ( https://www.developerlibs.com/2018/11/flutter-firebase-realtime-database-crud.html ).我从该站点复制代码( https://www.developerlibs.com/2018/11/flutter-firebase-realtime-database-crud.html )。 And here is my code's link, link of Git.这是我的代码链接,Git 的链接。 https://github.com/hannan228/flutter-with-firebase.git https://github.com/hannan228/flutter-with-firebase.git

pubspec.yaml code is here pubspec.yaml code name: databaseinflutter description: A new Flutter application. pubspec.yaml代码在这里

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.7.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.3
  firebase_database: ^1.0.5
  http: "^0.11.3+17"
  firebase_auth: 0.16.1
  #firebase_auth: 0.6.2+1
  google_sign_in: ^3.2.1
  fluttertoast: ^2.0.7
  flutter_svg: ^0.6.1+1

dev_dependencies:
  flutter_test:
    sdk: flutter
# The following section is specific to Flutter.
flutter:
  uses-material-design: true

app/build.gradle is same as app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.yovin.databaseinflutter"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.android.support:multidex:1.0.3' //for multidex

    implementation 'com.google.firebase:firebase-analytics:17.4.3'
    implementation 'com.google.firebase:firebase-auth:19.3.1'
    implementation 'com.google.firebase:firebase-firestore:21.4.3'

}

android/build.gradle is as android/build.gradle 是

    buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        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
}
apply plugin: 'com.google.gms.google-services'

here is GeneratedPluginRegistrant.java file这是 GeneratedPluginRegistrant.java 文件

here is screenshot of some error这是一些错误的屏幕截图

Following is complete errors that are showing in Console以下是控制台中显示的完整错误

Running Gradle task 'assembleDebug'... C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:8: error: package android.support.annotation does not exist import android.support.annotation.NonNull;运行 Gradle 任务 'assembleDebug'... C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\s io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:8: error: package android.support.annotation does not exist import android.support.annotation.NonNull; ^ C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:538: error: cannot find symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull location: class FirebaseAuthPlugin.SignInCompleteListener C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:558: error: cannot find symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull location: class FirebaseAuthPlugin.TaskVoidCompleteListener C:\flutter\flutter_windows_1.17.4-stabl ^ C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\ FirebaseAuthPlugin.java:538: error: cannot find symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull location: class FirebaseAuthPlugin.SignInCompleteListener C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted \pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:558:错误:找不到符号 public void onComplete(@NonNull Task task ) { ^ 符号:class NonNull 位置:class FirebaseAuthPlugin.TaskVoidCompleteListener C:\flutter\4-flutter_blow.7. e\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:576: error: cannot find symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull location: class FirebaseAuthPlugin.ProvidersCompleteListener C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:175: error: cannot find symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.Z93F725A07423FE1C889F e\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:576:错误:找不到symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull location: class FirebaseAuthPlugin.ProvidersCompleteListener C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6 .2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:175: error: cannot find symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull C:\ flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.Z93F725A07423FE1C889F 448B33D21F46Z:270: error: cannot find symbol public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { ^ symbol: class NonNull C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:435: error: cannot find symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:487: error: cannot find symbol public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { ^ symbol: class NonNull Note: C:\flutter\flutter_w 448B33D21F46Z:270: error: cannot find symbol public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { ^ symbol: class NonNull C:\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth -0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:435: error: cannot find symbol public void onComplete(@NonNull Task task) { ^ symbol: class NonNull C :\flutter\flutter_windows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin。 java:487: 错误: 找不到符号 public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { ^ 符号: class NonNull 注意: Z0D61F8370CAD11D61F8370CAD1D4flutter_w2F70B8E indows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java uses or overrides a deprecated API. indows_1.17.4-stable\flutter.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java 使用或覆盖已弃用的 API。 Note: Recompile with -Xlint:deprecation for details.注意:使用 -Xlint:deprecation 重新编译以获取详细信息。 8 errors 8 个错误

FAILURE: Build failed with an exception. FAILURE:构建失败并出现异常。

  • What went wrong: Execution failed for task ':firebase_auth:compileDebugJavaWithJavac'.出了什么问题:任务':firebase_auth:compileDebugJavaWithJavac'的执行失败。

Compilation failed;编译失败; see the compiler error output for details.有关详细信息,请参阅编译器错误 output。

  • Try: Run with --stacktrace option to get the stack trace.尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.使用 --info 或 --debug 选项运行以获得更多日志 output。 Run with --scan to get full insights.运行 --scan 以获得完整的见解。

  • Get more help at https://help.gradle.orghttps://help.gradle.org获得更多帮助

BUILD FAILED in 1m 14s The built failed likely due to AndroidX incompatibilities in a plugin. BUILD FAILED in 1m 14s 构建失败可能是由于插件中的 AndroidX 不兼容。 The tool is about to try using Jetfier to solve the incompatibility.该工具即将尝试使用Jetfier解决不兼容问题。 Building plugin firebase_auth... Running Gradle task 'assembleAarRelease'... √ Built build\app\outputs\repo.构建插件 firebase_auth... 运行 Gradle 任务 'assembleAarRelease'... √ 构建 build\app\outputs\repo。 Building plugin firebase_core... Running Gradle task 'assembleAarRelease'... √ Built build\app\outputs\repo.构建插件 firebase_core... 运行 Gradle 任务 'assembleAarRelease'... √ 构建 build\app\outputs\repo。 Building plugin firebase_database... Running Gradle task 'assembleAarRelease'... √ Built build\app\outputs\repo.构建插件 firebase_database... 运行 Gradle 任务 'assembleAarRelease'... √ 构建 build\app\outputs\repo。 Building plugin fluttertoast... Running Gradle task 'assembleAarRelease'... √ Built build\app\outputs\repo.构建插件 fluttertoast... 运行 Gradle 任务 'assembleAarRelease'... √ 构建 build\app\outputs\repo。 Building plugin google_sign_in... Running Gradle task 'assembleAarRelease'... √ Built build\app\outputs\repo.构建插件 google_sign_in... 运行 Gradle 任务 'assembleAarRelease'... √ 构建 build\app\outputs\repo。 Running Gradle task 'assembleDebug'...运行 Gradle 任务“assembleDebug”...

FAILURE: Build failed with an exception. FAILURE:构建失败并出现异常。

  • What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'.出了什么问题:任务“:app:checkDebugDuplicateClasses”执行失败。

1 exception was raised by workers: java.lang.RuntimeException: Duplicate class com.google.android.gms.internal.measurement.zzu found in modules jetified-firebase-analytics-impl-16.2.2-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.2) and jetified-play-services-measurement-base-17.4.3-runtime.jar (com.google.android.gms:play-services-measurement-base:17.4.3) 1 exception was raised by workers: java.lang.RuntimeException: Duplicate class com.google.android.gms.internal.measurement.zzu found in modules jetified-firebase-analytics-impl-16.2.2-runtime.jar (com.google .firebase:firebase-analytics-impl:16.2.2) and jetified-play-services-measurement-base-17.4.3-runtime.jar (com.google.android.gms:play-services-measurement-base:17.4. 3)

BUILD FAILED in 3m 49s Exception: Gradle task assembleDebug failed with exit code 1 BUILD FAILED in 3m 49s Exception: Gradle task assembleDebug failed with exit code 1

error: package android.support.annotation does not exist import android.support.annotation.NonNull;

The above error says that your project is made with androidx dependency but the problem is with auth package.上述错误表明您的项目是使用 androidx 依赖项制作的,但问题出在 auth package 上。

I can see you are using firebase_auth package of version 0.6.2 which is before the breaking change of "Migrating to AndroidX".我可以看到您正在使用版本 0.6.2 的 firebase_auth package,这是在“迁移到 AndroidX”的重大更改之前。 Also in your Android dependencies同样在您的 Android 依赖项中

    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.android.support:multidex:1.0.3'

you are mixing androidx and support libraries.您正在混合 androidx 和支持库。 Android support library nomenclature that is com.android.support:X is deprecated and should no longer be used and should be replaced by the newer androidx dependencies. Android 支持库命名为com.android.support:X已弃用,不应再使用,应由较新的androidx依赖项替换。 Mixing the two with a very outdated package ( firebase_auth is currently at 0.16) will lead to such error.将两者与非常过时的 package( firebase_auth当前为 0.16)混合会导致此类错误。

In conclusion, your error should be resolved if you jumped your firebase_auth version to the latest ( firebase_auth 0.16.1 ) and replace multidex dependency to 'androidx.multidex:multidex:2.0.1总之,如果您将 firebase_auth 版本跳到最新版本( firebase_auth 0.16.1 )并将 multidex 依赖项替换为'androidx.multidex:multidex:2.0.1

You can read more about AndroidX and Multidex here:您可以在此处阅读有关 AndroidX 和 Multidex 的更多信息:

  1. https://developer.android.com/jetpack/androidx/ https://developer.android.com/jetpack/androidx/
  2. What is AndroidX? 什么是安卓X?
  3. https://developer.android.com/studio/build/multidex https://developer.android.com/studio/build/multidex

Hopefully, this solves your error.希望这可以解决您的错误。 Drop a comment otherwise or edit your answer with the new error.否则请删除评论或使用新错误编辑您的答案。 INclude your pubsec.yaml file in case too包括您的 pubsec.yaml 文件以防万一

暂无
暂无

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

相关问题 配置项目“:firebase_auth”时出现问题? - A problem occurred configuring project ':firebase_auth'? Flutter firebase_auth signInWithCredential 不适用于 android - Flutter firebase_auth signInWithCredential is not working on android Dart Flutter 顺序 firebase_auth 错误 - Dart Flutter sequential firebase_auth errors 评估项目“:firebase_auth”时出现问题 - A problem occurred evaluating project ':firebase_auth' Flutter 和 Firebase:任务 &#39;:firebase_auth:compileDebugJavaWithJavac&#39; 执行失败 - Flutter and Firebase: Execution failed for task ':firebase_auth:compileDebugJavaWithJavac' 我无法在 Flutter 中同时添加 cloud_firestore 和 firebase_auth - I cannot add cloud_firestore and firebase_auth together in Flutter Flutter 应用程序错误将尝试与 Firebase 和 Auth 连接 - Flutter app errors will trying to connect with Firebase and Auth 我想在我的Android应用程序中使用Firebase UI Auth,但是当我添加依赖项时,gradle显示错误 - I wanted to use Firebase UI Auth in my android app but when I add the dependency, the gradle shows an error 尝试使用 firebase 运行我的 Android 应用程序时遇到问题 - I have a problem when trying to run my Android application with firebase 我正在尝试将 firebase 添加到我的 flutter 项目中,但我不断收到此错误找不到方法实现() - I'm trying to add firebase to my flutter project but i keep on getting this Error Could not find method implementation()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM