#StackBounty: #selenium #gradle #appium #proguard #obfuscation duplicate class definitions while obfuscating Appium based jar using Pro…

Bounty: 50

I’m building a java application which uses Appium to automate a mobile app. I’m using Gradle to manage the dependencies.

The project compiles and builds the jar successfully but while obfuscating using gradle proguardtask, following errors are observed.

> Task :proguardTask
Note: there were 57 duplicate class definitions.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':proguardTask'.
Caused by: org.gradle.api.UncheckedIOException: java.io.IOException: 
Can't write [/home/mmt/eclipse-workspace/MobileTest/build/libs/MobileTest-0.1-obfus.jar] 
(Can't read [/home/mmt/eclipse-workspace/MobileTest/build/libs/MobileTest-0.1.jar] 
(Duplicate jar entry [org/openqa/selenium/SearchContext.class]))

I tried excludeing the dependencies which are transitive with no luck.

Tried doing transitive = false and adding the transitive one manually still couldn’t get the desired output.

Following is my build script.


    buildscript {
    repositories {
    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:6.1.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 { 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 {


-keepattributes Signature
-keepattributes Exceptions
-keep public class com.mobile.MobileTest.App {*;}
-keep class module-info{*;}

-keep public class com.beust.testng.**{*;}
-keep public interface com.beust.testng.**{*;}
-keep public enum com.beust.testng.**{*;}

-keep public class org.apache.log4j.**{*;}
-keep public interface org.apache.log4j.**{*;}
-keep public enum org.apache.log4j.**{*;}

-keep public class io.appium.java_client.**{*;}
-keep public interface io.appium.java_client.**{*;}
-keep public enum io.appium.java_client.**{*;}

-keep public class kobaltBuild.classes.**{*;}
-keep public interface kobaltBuild.classes.**{*;}
-keep public enum kobaltBuild.classes.**{*;}

-keep public class net.sourceforge.tess4j.**{*;}
-keep public interface net.sourceforge.tess4j.**{*;}
-keep public enum net.sourceforge.tess4j.**{*;}

-keep public class org.**{*;}
-keep public interface org.**{*;}
-keep public enum org.**{*;}

-keep public class scripts.**{*;}
-keep public interface scripts.**{*;}
-keep public enum scripts.**{*;}

-keep public class src.main.resources.**{*;}
-keep public interface src.main.resources.**{*;}
-keep public enum src.main.resources.**{*;}

-keep public class tessdata.**{*;}
-keep public interface tessdata.**{*;}
-keep public enum tessdata.**{*;}

-keep public class com.recognition.software.jdeskew.**{*;}
-keep public interface com.recognition.software.jdeskew.**{*;}
-keep public enum com.recognition.software.jdeskew.**{*;}

-keep public class bsh.**{*;}
-keep public interface bsh.**{*;}
-keep public enum bsh.**{*;}

-keep public class java.**{*;}
-keep public interface java.**{*;}
-keep public enum java.**{*;}

-keep public class javax.**{*;}
-keep public interface javax.**{*;}
-keep public enum javax.**{*;}

-keep public class org.**{*;}
-keep public interface org.**{*;}
-keep public enum org.**{*;}

Any pointer in the right direction is much appreciated.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.