Android Question Crash due to Google Ads Identifier on devices below API 26

In our application with the package name com.example.testapp, we are experiencing a crash when using the Google Play Services Ads Identifier. The crash occurs on devices running Android versions below API 26. The error log is as follows:

Fatal Exception: java.lang.NoClassDefFoundError
Failed resolution of: Ljava/time/Duration;
com.google.android.gms.ads.identifier.zzd.<clinit> (com.google.android.gms:play-services-ads-identifier@@18.2.0:1)
java.lang.Thread.run (Thread.java:818)
Caused by java.lang.ClassNotFoundException
Didn't find class "java.time.Duration" on path: DexPathList[[zip file "/data/app/com.example.testapp-1/base.apk", ... ]]
Analysis:


  • The crash is caused by the usage of java.time.Duration, which is only available on Android API 26 and above.
  • The library play-services-ads-identifier is not compatible with devices running lower API levels.
  • We are using the latest version of the AdMob library, the latest Android SDK, and B4A version 3.40.

Request:
Please investigate and provide a solution or guidance on how to safely use the Google Ads Identifier library on devices with API levels below 26 without causing a crash.
 

hatzisn

Expert
Licensed User
Longtime User
In our application with the package name com.example.testapp, we are experiencing a crash when using the Google Play Services Ads Identifier. The crash occurs on devices running Android versions below API 26. The error log is as follows:


Analysis:


  • The crash is caused by the usage of java.time.Duration, which is only available on Android API 26 and above.
  • The library play-services-ads-identifier is not compatible with devices running lower API levels.
  • We are using the latest version of the AdMob library, the latest Android SDK, and B4A version 3.40.

Request:
Please investigate and provide a solution or guidance on how to safely use the Google Ads Identifier library on devices with API levels below 26 without causing a crash.

Beside what @Erel wrote if you see this page it clearly states that Android devices bellow api 26 represent just a 5.2% of the pie. It might not worth it to get into trouble for such kind of small piece of the pie.
 
Upvote 0
You are correct. Google Ads SDK is now compatible with Android 8+ (API 26+). I will add it to the tutorial. You will need to use an older version of Google libraries or set the minSdkVersion to 26.
This error has also been recorded for Android 11
Fatal Exception: java.lang.NoClassDefFoundError
Failed resolution of: Ljava/time/Duration;
com.google.android.gms.ads.identifier.zzd.<clinit> (com.google.android.gms:play-services-ads-identifier@@18.2.0:1)

java.lang.Thread.run (Thread.java:831)
 
Upvote 0
1. This error happens in Google SDK.
2. The java.time package should be available in Android 8+: https://developer.android.com/reference/java/time/package-summary
If it isn't there then it might be an Android 11 with a broken OS (maybe a partially updated OS).
I asked the GPT chat, and they gave me this solution for Android Studio android
{
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
coreLibraryDesugaringEnabled true
}
}
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
}
Can this solution also be implemented for b4a?
 
Upvote 0
Top