I am trying to obfuscate a java application project which uses appium jars.
When I create the jar using gradle build the jar works fine but when I obfuscate the jar and try to run it I get the following error.
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 77
Exception Details:
Location:
com/mobile/MobileTest/App.peformActions()V @0: new
Reason:
Expected stackmap frame at this location.
Bytecode:
0x0000000: bb00 1859 b700 254d 2c12 0c12 02b6 0026
0x0000010: 2c12 0812 0db6 0026 2c12 0412 05b6 0026
0x0000020: 2c12 0312 06b6 0026 bb00 1259 bb00 1559
0x0000030: 120a b700 232c b700 204c 2b12 01b8 0024
0x0000040: b600 1f4e 2db9 0027 0100 a700 084c 2bb6
0x0000050: 0021 b1
Exception Handler Table:
bci [0, 74] => handler: 77
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
I have also visited many similar questions but none of them solved my issue
- ProGuard JNI Error
- Proguard - Error: A JNI error has occured
I have tried using -dontpreverify it did not work for me
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "net.sf.proguard:proguard-gradle:6.1.1"
}
}
plugins {
id 'java'
id 'maven-publish'
}
repositories {
maven {
url = 'http://repo.maven.apache.org/maven2'
}
}
dependencies {
compile 'org.testng:testng:6.14.3'
compile 'io.appium:java-client:7.0.0'
compile 'org.apache.poi:poi:3.16'
compile 'net.sourceforge.tess4j:tess4j:4.3.0'
compile 'log4j:log4j:1.2.17'
testCompile 'junit:junit:4.11'
}
group = 'com.mobile'
version = '0.1'
description = 'AppiumTest'
sourceCompatibility = '1.8'
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
jar{
duplicatesStrategy = 'exclude'
from { configurations.compile.collect { zipTree(it) } }
manifest {
attributes 'Implementation-Title': 'Jar File with dependencies',
'Implementation-Version': version,
'Main-Class': 'com.mobile.MobileTest.App'
}
}
task proguardTask(type: proguard.gradle.ProGuardTask,dependsOn: jar) {
configuration file('proguard.pro')
injars 'build/libs/MobileTest-0.1.jar'
outjars 'build/libs/MobileTest-0.1-obfus.jar'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
test {
useTestNG()
}
proguard.config
-dontoptimize
-allowaccessmodification
-dontshrink
-dontwarn
-dontpreverify
-verbose
-keepattributes Signature
-keepattributes Exceptions
-adaptclassstrings
-keepdirectories
-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;}
-keep public class com.mobile.MobileTest.App {*;}
-keepclassmembernames public class com.mobile.MobileTest.App {*;}
-keep class module-info{*;}
-keep public class afu.**{*;}
-keep public interface afu.**{*;}
-keep public enum afu.**{*;}
-keep public class aj.org.objectweb.asm.**{*;}
-keep public interface aj.org.objectweb.asm.**{*;}
-keep public enum aj.org.objectweb.asm.**{*;}
-keep public class bsh.**{*;}
-keep public interface bsh.**{*;}
-keep public enum bsh.**{*;}
-keep public class ch.qos.logback.**{*;}
-keep public interface ch.qos.logback.**{*;}
-keep public enum ch.qos.logback.**{*;}
-keep public class com.beust.**{*;}
-keep public interface com.beust.**{*;}
-keep public enum com.beust.**{*;}
-keep public class com.github.jaiimageio.**{*;}
-keep public interface com.github.jaiimageio.**{*;}
-keep public enum com.github.jaiimageio.**{*;}
-keep public class com.google.**{*;}
-keep public interface com.google.**{*;}
-keep public enum com.google.**{*;}
-keep public class com.lowagie.**{*;}
-keep public interface com.lowagie.**{*;}
-keep public enum com.lowagie.**{*;}
-keep public class com.ochafik.lang.jnaerator.runtime.**{*;}
-keep public interface com.ochafik.lang.jnaerator.runtime.**{*;}
-keep public enum com.ochafik.lang.jnaerator.runtime.**{*;}
-keep public class com.recognition.software.jdeskew.**{*;}
-keep public interface com.recognition.software.jdeskew.**{*;}
-keep public enum com.recognition.software.jdeskew.**{*;}
-keep public class com.sun.jna.**{*;}
-keep public interface com.sun.jna.**{*;}
-keep public enum com.sun.jna.**{*;}
-keep public class gnu.cajo.**{*;}
-keep public interface gnu.cajo.**{*;}
-keep public enum gnu.cajo.**{*;}
-keep public class images.**{*;}
-keep public interface images.**{*;}
-keep public enum images.**{*;}
-keep public class io.appium.java_client.**{*;}
-keep public interface io.appium.java_client.**{*;}
-keep public enum io.appium.java_client.**{*;}
-keep public class javax.annotation.**{*;}
-keep public interface javax.annotation.**{*;}
-keep public enum javax.annotation.**{*;}
-keep public class kobaltBuild.classes.**{*;}
-keep public interface kobaltBuild.classes.**{*;}
-keep public enum kobaltBuild.classes.**{*;}
-keep public class mozilla.**{*;}
-keep public interface mozilla.**{*;}
-keep public enum mozilla.**{*;}
-keep public class net.**{*;}
-keep public interface net.**{*;}
-keep public enum net.**{*;}
-keep public class okhttp3.**{*;}
-keep public interface okhttp3.**{*;}
-keep public enum okhttp3.**{*;}
-keep public class okio.**{*;}
-keep public interface okio.**{*;}
-keep public enum okio.**{*;}
-keep public class org.**{*;}
-keep public interface org.**{*;}
-keep public enum org.**{*;}
Any kind of help would be appreciated.