flutter import android.support.annotation.NonNull



所以,我想在颤音中使用firebase_auth,但是我有androidx.annotation.annotation.nonnull错误,我对Android文件进行了几个更改错误,但现在我得到

错误

C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:8: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:538: error: cannot find symbol
    public void onComplete(@NonNull Task<AuthResult> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.SignInCompleteListener
C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:558: error: cannot find symbol
    public void onComplete(@NonNull Task<Void> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.TaskVoidCompleteListener
C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:576: error: cannot find symbol
    public void onComplete(@NonNull Task<ProviderQueryResult> task) {
                            ^
  symbol:   class NonNull
  location: class FirebaseAuthPlugin.ProvidersCompleteListener
C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:175: error: cannot find symbol
                      public void onComplete(@NonNull Task<AuthResult> task) {
                                              ^
  symbol: class NonNull
C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:270: error: cannot find symbol
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                                          ^
  symbol: class NonNull
C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:435: error: cannot find symbol
              public void onComplete(@NonNull Task<GetTokenResult> task) {
                                      ^
  symbol: class NonNull
C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java:487: error: cannot find symbol
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                                          ^
  symbol: class NonNull
Note: C:UsersDellflutter.pub-cachehostedpub.dartlang.orgfirebase_auth-0.6.2+1androidsrcmainjavaioflutterpluginsfirebaseauthFirebaseAuthPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
8 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 7s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                         8.5s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See  .... for more information on the problem and how to fix it.
*******************************************************************************************
Gradle task assembleDebug failed with exit code 1

android/gradle.properties

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX = true
android.enableJetifier = true

android/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.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.example.proapp"
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    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.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

pubspec.yaml

    name: pro_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.
    # Read more about versioning at semver.org.
    version: 1.0.0+1
    environment:
      sdk: ">=2.1.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
      sqflite:
      path_provider: any
      intl:
      flutter_svg:
      charts_flutter:
      # firebase
      cloud_firestore:  
      firebase_auth:
      # firebase_core:  
    dev_dependencies:
      flutter_test:
        sdk: flutter
.......

注意:我已经尝试更改compilesdkversion和 targetsdkversion到27,但后来我得到了app:processDebugresources错误。

这个问题似乎是由Androidx迁移问题引起的。有两种方法可以在现有项目中添加Androidx支持。您可以通过Android Studio或运行flutter create...进行迁移。如果您仍然有问题,我建议运行flutter doctor -v检查任何错误和警告。

最新更新