java.lang.NoClassDefFoundError: java.util.Objects

前端 未结 2 1967
囚心锁ツ
囚心锁ツ 2020-12-06 11:06

I\'m getting the following crash report in Android development Console. My app runs fine on the simulator or devices that I tried the app on, but for some reason on a Galaxy

相关标签:
2条回答
  • 2020-12-06 11:57

    The exception is thrown because all static methods of java.util.Objects are available above API 19 (Android 4.4.+).

    As you said in comments, your device has API 10 (Android 2.3.+) so that method doesn't exist in that Android version and NoClassDefFoundError is thrown.

    If you want to check api level programmatically you can do:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // your code available only above api 19
    } else {
        // compatibility code
    }
    
    0 讨论(0)
  • 2020-12-06 11:59

    In my case this exception happened on Android 4 after upgrade to Retrofit 2.7.1. See https://github.com/square/retrofit/blob/master/CHANGELOG.md:

    Version 2.7.0 (2019-12-09)

    This release changes the minimum requirements to Java 8+ or Android 5+. See this blog post for more information on the change.

    New: Upgrade to OkHttp 3.14.4. Please see its changelog for 3.x.
    

    See also https://github.com/square/retrofit/issues/3201 and https://github.com/square/retrofit/issues/3042.

    Retrofit depends on OkHttp that refused pre API 21 support in version 3.13.

    So, downgrade Retrofit to 2.6.4 or even before 2.6.0. I checked, it solved the problem. Also downgrade Retrofit Gson converter (com.squareup.retrofit2:converter-gson) to 2.6.4.

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