broadlink-java-api
broadlink-java-api copied to clipboard
Replace javax.xml.bind.DatatypeConverter with java.util.Base64 for Java 9+ compatibility
Description
This PR addresses the issue where the library fails to run on Android and newer versions of Java (Java 9+) due to the use of javax.xml.bind.DatatypeConverter, which has been removed in newer Java versions and is not available in Android's runtime. The changes replace javax.xml.bind.DatatypeConverter with java.util.Base64, which is compatible with Android, Java SE, and newer versions of Java.
Changes:
- Replaced
DatatypeConverter.parseBase64Binary()withBase64.getDecoder().decode() - Replaced
DatatypeConverter.printBase64Binary()withBase64.getEncoder().encodeToString()
Why is this change necessary?
-
javax.xml.bind.DatatypeConverteris not available in Android, causing aNoClassDefFoundErrorwhen the library is used in Android apps. -
javax.xml.bind.DatatypeConverterhas been removed in Java 9 and later, making the library incompatible with newer Java versions. -
java.util.Base64is a standard Java class available in both Android and Java SE (including newer versions), making the library more versatile and future-proof.
Testing:
- The changes were tested on an Android app, and the library now works without throwing the
NoClassDefFoundError. - The changes were also tested on a Java SE environment (Java 17) to ensure compatibility with newer Java versions.
- Existing functionality was verified to ensure no regressions were introduced.
Related Issue:
- Fixes #123 (if there is an existing issue, link it here)