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

Viewed 1507

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?

2 Answers

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.

In Android Studio preferences, you can turn off Instant Run. This seemed to fix the issue for our app's build without any other changes. It's in Preferences > Build, Execution, Environment > Instant Run.

Related