Flutter Error: java.lang.NoSuchFieldError PREFER_HIGHEST_OR_REMOTE_VERSION_NO_FORCE_STAGING

后端 未结 3 1549
予麋鹿
予麋鹿 2020-12-30 18:07

I have tried to solve this problem but it keeps giving me the same error.

I use the following firebase services:

  • Firebase Auth
  • Firebase Databa
相关标签:
3条回答
  • 2020-12-30 18:23

    The Beardo's Answer Solves the Issue,

    Please Look at my gradle files.

    App Level: -

    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 27
    
        lintOptions {
            disable 'InvalidPackage'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.adilstore.rakeshproject"
            minSdkVersion 16
            targetSdkVersion 27
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
        }
    
        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'
        implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
        implementation 'com.google.firebase:firebase-core:16.0.4'
        implementation 'com.google.firebase:firebase-analytics:16.0.4'
        implementation 'com.google.firebase:firebase-auth:16.0.4'
        implementation 'com.google.firebase:firebase-firestore:17.1.1'
        implementation 'com.google.firebase:firebase-functions:16.1.1'
        implementation 'com.google.firebase:firebase-messaging:17.3.3'
        implementation 'com.google.firebase:firebase-storage:16.0.3'
    }
    apply plugin: 'com.google.gms.google-services'
    //com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
    

    And Project Level:-

    buildscript {
        repositories {
            google()
            jcenter()
            mavenCentral() //add this 
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.2'
            classpath 'com.google.gms:google-services:3.2.1'
        }
    }
    
    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
    }
    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "26.1.0"
                }
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-30 18:26

    In my case upgrading everything to the latest versions helped. Here are the steps:

    • Open the Android project as a separate project
    • Upgrade Gradle
    • Upgrade all the Firebase-related dependencies
    • Migrate to Androidx if needed
    • Go back to the parent Flutter project
    • Upgrade all the Firebase-related dependencies there (i.e., search for the latest versions at https://pub.dev/packages, update them and run flutter --no-color packages upgrade or just click Packages upgrade in the main pubspec.yaml
    • Upgrade the Flutter itself by running flutter --no-color upgrade or clicking Flutter upgrade
    0 讨论(0)
  • 2020-12-30 18:28

    I believe that this is due to the fact that half of Google's FlutterFire plugins are using old versions of their Android counterparts. As such, I've specified which versions to use in my app level build.gradle. This probably isn't a permanent solution, but seems to have stopped the crashes in the mean time.

    In the app level build.gradle, add the following to dependencies:

    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-analytics:16.0.4'
    implementation 'com.google.firebase:firebase-auth:16.0.4'
    implementation 'com.google.firebase:firebase-firestore:17.1.1'
    implementation 'com.google.firebase:firebase-functions:16.1.1'
    implementation 'com.google.firebase:firebase-messaging:17.3.3'
    implementation 'com.google.firebase:firebase-storage:16.0.3'
    

    Let me know if this works.

    Edit: Only add the implementation lines for the Firebase plugins that you are using. You can find the latest version of each here.

    0 讨论(0)
提交回复
热议问题