I am getting the following error during runtime when running my app: java.lang.NoSuchMethodError: No virtual method setTokenProvider

huangapple go评论155阅读模式
英文:

I am getting the following error during runtime when running my app: java.lang.NoSuchMethodError: No virtual method setTokenProvider

问题

在从Android Studio的模拟器中运行我的应用程序时,我遇到了以下错误。该应用程序成功编译。

java.lang.NoSuchMethodError:在类Lcom/google/firebase/FirebaseApp中找不到虚拟方法setTokenProvider(Lcom/google/firebase/internal/InternalTokenProvider;)V,或者在其父类中找不到('com.google.firebase.FirebaseApp'的声明出现在/data/app/~~_7zL9Id2RK7b6zEuTNlmiQ==/com.example.abc_supermarket-2V5eMXxz7SuahQK49NOpSw==/base.apk中)

我的Gradle文件:

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

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.abc_supermarket"
        minSdkVersion 14
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'com.google.firebase:firebase-database:19.5.0'
    implementation 'com.google.firebase:firebase-storage:19.2.0'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    // For Card view
    implementation 'androidx.cardview:cardview:1.0.0'

    // Chart and graph library
    implementation 'com.github.blackfizz:eazegraph:1.2.5l@aar'
    implementation 'com.nineoldandroids:library:2.4.0'

    repositories {
        maven { url 'https://jitpack.io' }
    }

    dependencies {
        implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    }

    android {
        lintOptions {
            checkReleaseBuilds false
            // Or, if you prefer, you can continue to check for errors in release builds,
            // but continue the build even when errors are found:
            abortOnError false
        }
    }
}

在我向应用程序添加Firebase Storage后,这个错误只开始出现。我在Stack Overflow上只找到一个关于这个错误的帖子,但提供的唯一解决方案对我没有起作用。关于这个特定错误的在线信息似乎不多,所以我在这里急需帮助。非常感谢任何回复。

附注:我在使用Android Studio方面还是比较新手。

英文:

I am encountering this error when running my app in an emulator from Android Studio. The app compiles successfully.

> java.lang.NoSuchMethodError: No virtual method setTokenProvider(Lcom/google/firebase/internal/InternalTokenProvider;)V in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/~~_7zL9Id2RK7b6zEuTNlmiQ==/com.example.abc_supermarket-2V5eMXxz7SuahQK49NOpSw==/base.apk)

My Gradle

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

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.abc_supermarket"
        minSdkVersion 14
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'com.google.firebase:firebase-database:19.5.0'
    implementation 'com.google.firebase:firebase-storage:19.2.0'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'


// For Card view
    implementation 'androidx.cardview:cardview:1.0.0'

// Chart and graph library
    implementation 'com.github.blackfizz:eazegraph:1.2.5l@aar'
    implementation 'com.nineoldandroids:library:2.4.0'

    repositories {
        maven { url 'https://jitpack.io' }
    }

    dependencies {
        implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

    }

    android {
        lintOptions {
            checkReleaseBuilds false
            // Or, if you prefer, you can continue to check for errors in release builds,
            // but continue the build even when errors are found:
            abortOnError false
        }
    }


}

The error only started occurring after I added Firebase Storage to my app. I have found only one other post about this error on SO and the only solution provided did not work for me. There doesn't seem to be much information about this particular error online so I am coming here in desperate need of help. All responses are greatly appreciated I am getting the following error during runtime when running my app: java.lang.NoSuchMethodError: No virtual method setTokenProvider

PS. I am still quite new to working with Android Studio

答案1

得分: 0

也许是因为你正在使用旧版的 Firebase 认证,而同时又在使用最新版的 Firebase 存储。关于这个问题,Firebase 发布说明 提供了详细信息:

implementation 'com.google.firebase:firebase-auth:16.0.5'

> 这次更新的重要变化包括:
> - 如果你在使用 Firebase 认证,务必将 firebase-auth 更新至 v17.0.0 或更新的版本,以确保其功能与其他已更新的 Firebase 库保持一致。
> - 几个库将最低支持的 Android API 版本升级至 16,以符合 Google Play 服务的分发政策。
> - 在项目级别的 build.gradle 文件中,确保在 buildscript 和 allprojects 部分都包含了 Google 的 Maven 仓库。

只需将其更新到新版本的 Firebase 认证即可。

英文:

Maybe it's because you're using old firebase auth and latest firebase storage and Firebase release notes provided details :

implementation 'com.google.firebase:firebase-auth:16.0.5'

> Breaking changes for this update:
> - If you use Firebase Authentication, update to firebase-auth v17.0.0 or later to ensure functionality alignment with other updated Firebase libraries.
> - Several libraries updated minSdkVersion to API level 16 to align with the Google Play
> services distribution policy.
> - In your project-level build.gradle file, make sure to include Google's Maven repository in both your buildscript and allprojects sections.

Just change it to new version of firebase auth

huangapple
  • 本文由 发表于 2020年10月27日 18:39:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64552648.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定