Hakky54/sslcontext-kickstart

android 6.0 Caused by: java.lang.NoClassDefFoundError

Closed this issue · 5 comments

Describe the bug
I use android 12、13 platform is work.But use android 6 is crash.

code:

SSLFactory sslFactory = SSLFactory.builder().withTrustMaterial(bks file, password).build
crash log

Caused by: java.lang.NoClassDefFoundError: nl.altindag.ssl.util.KeyStoreUtils$$ExternalSyntheticLambda0 at nl.altindag.ssl.util.KeyStoreUtils.<clinit>(KeyStoreUtils.java:56) at nl.altindag.ssl.SSLFactory$Builder.withTrustMaterial(SSLFactory.java:366)

Expected behavior
I generate SSLSocketFactory crash

Screenshots
image

Environmental Data:

  • android targetsdkversion 32
  • android compilesdkversion 32
  • java 8
  • Gradle: io.github.hakky54:sslcontext-kickstart:7.4.9

I noticed your file is a bks (bouncy castle keystore) file and the library is using pkcs12 as keystore type by default. So I am guessing it might be related to that.

Can you validate if you have the following library on your classpath: org.bouncycastle:bcpkix-jdk15on:1.70.
If it is not present can you try to add it.

And can you run your sslfactory with the following code snippet:

SSLFactory sslFactory = SSLFactory.builder()
    .withTrustMaterial(bks file, password, "BKS")
    .build

If nothing is provided it will use the default which is pkcs12.

Please give it a try and let me know if you have some results

@Hakky54 Thanks for replying,I add classpath org.bouncycastle:bcpkix-jdk15on:1.70 and add trustStoreType with BKS.
But carsh log is same.

image

I try android 13、12、11、10、9、8、7 is work, only 6 is crash.

It seems like Android 6 is not compatible with Java 8. It is however compatible with Java 7, but this library is made compatible for Java version 8 and newer. So Therefor it won't work on android 6 and that explains your error. The exception refers to java.util.function.UnaryOperator which I use in the KeyStoreUtils which does not exists in Java 7. See here also for the list which Google has listed https://source.android.com/docs/setup/start/older-versions#jdk

By the way, why do you want to make your project compatible with Android 6?

@Hakky54 Thanks explain the reason. Google Play App almost support 5.0 or 6.0 version up, so my project must be compatible with Android 6, app user report to google play crash, so I must be to fix it. If this library can't compatible with Android 6... I maybe give up this library QAQ

I see, you have users which are on Android 6 and they have this issue.

I did someinvestigation to make this library compatible with Java 7, however alot of classes needs to be rewritten as it haveliy depends on the language features of Java 8 such as Lambda's, Optionals, Streaming Collections and Functional Interfaces. Next to that it will have breaking changes which I don't want to happen. So I won't be making this library compatible with Java 7.

An option for you would be maybe copying code snippets from this library which you are using into your project. In that way you don't depend on the library and can adjust it to your needs, however the downside of this approach is that you won't be getting security patches, bug fixes and new features as you will be maintaining your own version.

Another option would be dropping the support for Android 6 as it is also not actively maintained/supported by Google. It has been released in 2015 and the last security patch is from 2018. I know it is good to support the lowest android level possible to reach the most amount of end-users and it makes it even harder when you already have users on that android version. So if it is not possible to drop the support for your application for Android 6, I would suggest to copy-past what you need from this library. Please make sure to include the original license header if you plan to copy the source code.