javaandroidmockitosamsung-mobile-sdkandroid-jetifier

AndroidX Jetifier Mockito java.lang.SecurityException: SHA-256 digest error for com/samsung/android/sdk/accessory/SAAgentV2.class


I am migrating my app to use AndroidX. I have enabled Jetifier in my gradle.properties file

android.useAndroidX=true
android.enableJetifier=true

I use mockito in some tests. After migration a few tests fail where mockito is not able to mock classes which use Samsung accessory sdks version 2.6.1 .

Part of exception log is as under

Caused by: java.lang.SecurityException: SHA-256 digest error for com/samsung/android/sdk/accessory/SAAgentV2.class at sun.security.util.ManifestEntryVerifier.verify(ManifestEntryVerifier.java:218) at java.util.jar.JarVerifier.processEntry(JarVerifier.java:241) at java.util.jar.JarVerifier.update(JarVerifier.java:228) at java.util.jar.JarVerifier$VerifierStream.read(JarVerifier.java:482) at sun.misc.Resource.getBytes(Resource.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:462)

I believe this happens due to a signed jar being edited by jetifier. What can be done to overcome this issue?


Solution

  • Couldn't find any answer for last 3 days, so I just removed META-INF from the samsung accessory jar.

    jar xvf accessory-2.6.1..jar
    
    rm -rf META-INF
    
    jar cvf accessory-2.6.1-updated..jar *
    

    Now will need to check if the accessory apis are working or not.