Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCStringDecoder base64 encoding failed on android api level <=25 #140

Open
af-jja opened this issue Jul 14, 2022 · 8 comments
Open

TCStringDecoder base64 encoding failed on android api level <=25 #140

af-jja opened this issue Jul 14, 2022 · 8 comments

Comments

@af-jja
Copy link

af-jja commented Jul 14, 2022

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?

@abhayIOS
Copy link

Any update on this issue?

@laktech
Copy link
Collaborator

laktech commented Apr 11, 2023

Ideally, we would vendorize the Base64 class and include it in the project. Are you familiar with any other android issues?

@abhayIOS
Copy link

I am not familiar with 'vendorize the Base64 class and include it' Can you please share an example?

@laktech
Copy link
Collaborator

laktech commented Apr 11, 2023

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.

@abhayIOS
Copy link

So you want us to include the lib code in the project replacing the Base64 import. Replacing the library reference.

@laktech
Copy link
Collaborator

laktech commented Apr 11, 2023

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.

@coldcode001
Copy link

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.

@silvagoncalodev
Copy link

@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:

  1. The java.time libraries introduced in Java 8 - this isn't an issue anymore because of Android Studio API desugaring, which supports older APIs;
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants