TCStringDecoder base64 encoding failed on android api level <=25
Version 2.0.10
Module (core, cmpapi, cli, stub, or testing) iabtcf-decoder
Error
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/util/Base64; at com.iabtcf.decoder.TCStringDecoder.vectorFromString(TCStringDecoder.java:37) at com.iabtcf.decoder.TCStringDecoder.decode(TCStringDecoder.java:57) at com.iabtcf.decoder.TCString.decode(TCString.java:43)
Describe with reproduction steps – What is the expected behavior? TCString decoding failed with an exception.
On andorid api level 25 and below, java.util.Base64 is not available. it should be replaced with android.util.Base64
see: https://stackoverflow.com/questions/48697766/android-studio-noclassdeffounderror-with-java-util-base64
is it possible to support an android/kotlin lib on maven as well?
Any update on this issue?
Ideally, we would vendorize the Base64 class and include it in the project. Are you familiar with any other android issues?
I am not familiar with 'vendorize the Base64 class and include it' Can you please share an example?
it means to include the code in the project so both android and non-android platforms can be supported. we essentially remove the dependency from the standard library. however, this approach only makes sense if all android dependencies are identified. if this is not possible other tactics would be required like creating two builds, one for each platform.
So you want us to include the lib code in the project replacing the Base64 import. Replacing the library reference.
correct, but again, all dependencies must be identified since some may be more feasible to include than others. in the event that a dependency cannot be easily included, this approach would not be successful.
If java.util.Base64 is the only one issue, then the reflection would make a workaround for Android. Just try and fallback with the android.util.Base64 instead in a helper class and use it for all cases. I saw there's similar issue in decoder lib.
@laktech I've been using the decoder library on Android projects, I might be able to help with this.
I downloaded your project, converted it to an Android Studio project and executed all unit tests as instrumentation tests on an Android device.
Currently, there are 2 hidden dependencies that result in crashes at runtime, on versions older than API 26:
- The java.time libraries introduced in Java 8 - this isn't an issue anymore because of Android Studio API desugaring, which supports older APIs;
- The java.util.Base64 class - this needs to be replaced with something that works on older Android APIs.
I replaced java.util.Base64 with android.util.Base64 equivalent methods, and all your unit tests complete successfully. So you just need to find an alternative to java.util.Base64 to officially support Android devices.