簡體   English   中英

java.lang.NoSuchMethodError: 沒有 static 方法 isAtLeastR()Z

[英]java.lang.NoSuchMethodError: No static method isAtLeastR()Z

我的應用程序運行良好,但突然出現此錯誤

java.lang.NoSuchMethodError:class Landroidx/core/os/BuildCompat 中沒有 static 方法 isAtLeastR()Z; 或其超類(“androidx.core.os.BuildCompat”的聲明出現在 /data/app/com.app.goflatmates-RZKwS2h6hav==/base.apk 中)位於 com.google.android.gms.common.util。 PlatformVersion.isAtLeastR(com.google.android.gms:play-services-basement@@17.2.0:21) 在 com.google.android.gms.common.api.GoogleApi.zaa(com.google.88429461:88429461) play-services-base@@17.2.0:128) 在 com.google.android.gms.common.api.GoogleApi.(com.google.android.gms:play-services-base@@17.2.0:23) at com.google.android.gms.common.api.GoogleApi.(com.google.android.gms:play-services-base@@17.2.0:54) at com.google.android.gms.auth.api. signin.GoogleSignInClient。(未知來源:3)位於 com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(未知來源:3

問題出在這一行

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build(); 

mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

我在 React Native 上也遇到了這個問題。 我通過在我的 app/build.gradle 中設置它來修復它:

dependencies {
    // ...
    implementation 'com.google.android.gms:play-services-base:17.1.0'
    // ...
}

這是因為幾天前 Google play-services-base 庫引入了一個重大變化。 如果您使用implementation 'com.google.android.gms:play-services-base:+'它會下載最新版本的庫,並將該錯誤引入您的應用程序。 希望有幫助。

/**
     * Checks if the device is running on a pre-release version of Android R or newer.
     * <p>
     * <strong>Note:</strong> This method will return {@code false} on devices running release
     * versions of Android. When Android R is finalized for release, this method will be deprecated
     * and all calls should be replaced with {@code Build.VERSION.SDK_INT >= Build.VERSION_CODES.R}.
     *
     * @return {@code true} if R APIs are available for use, {@code false} otherwise
     */
    public static boolean isAtLeastR() {
        return VERSION.CODENAME.length() == 1 && VERSION.CODENAME.charAt(0) >= 'R'
                && VERSION.CODENAME.charAt(0) <= 'Z';
    }

Android Q 是最終版本,不再需要此方法。 它將在支持庫的未來版本中刪除。

請降級版本

 implementation 'com.google.android.gms:play-services-base:17.1.0'
 implementation 'com.google.android.gms:play-services-base:17.0.0' //OR

錯誤在com.google.android.gms:play-services-base:17.2.0之前說降級到 17.1.0 的答案是正確的,但谷歌現在已經解決了這個問題,所以你可以升級到 17.2.1它也工作正常。

這三個是一起更新的,所以如果你正在使用它們,請將它們全部更新:

com.google.android.gms:play-services-base:17.2.1
com.google.android.gms:play-services-basement:17.2.1
com.google.android.gms:play-services-tasks:17.0.2

來源: https : //developers.google.com/android/guides/releases

我通過在我的 app/build.gradle 中設置它來修復它

dependencies {
    // ...
    configurations.all {
        resolutionStrategy.force 'com.google.android.gms:play-services-base:17.1.0'
    }
}

對我來說,在我構建 apk 后發生了與@jaymin 描述的相同的錯誤。

我的錯誤:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxx, PID: 11111
    java.lang.NoSuchMethodError: No static method loadImage$default(Landroid/widget/ImageView;Landroid/content/Context;Ljava/lang/String;Landroid/graphics/drawable/Drawable;ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;ZILjava/lang/Object;)V in class Lcom/...; or its super classes (declaration of 'com.xxx.xxx.android.commonui.GlideModuleKt' appears in /data/app/~~NHbxxxx_xxxxw==/com.xxx-kxx-xxxxxxxxxxxxxxxMA==/base.apk!classes8.dex)

(在此之前,該應用程序運行良好)。 為了修復它,我已經清除了緩存(build,idea,項目中的 gradle 和...用戶/.gradle 下),重新安裝應用程序和 Android Studio - 所有這一切都是徒勞的。

最后,我重命名了錯誤中提到的方法(例如loadImage to loadImageTwo and back to loadImage )並運行應用程序。 應用程序有效。 我已經創建了 apk,但使用新名稱 ( loeadImageTwo ) 仍然一切正常。 之后,我將方法重新命名為 ( loadImage ) 並重復了這些步驟,現在一切都很順利。

我花了一些時間才弄明白,所以如果這對其他人也有幫助,那將是值得的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM