1

Android Obfuscation (minifyEnabled true) not working in both Debug and Release minifyEnabled - true is not working for android in debug mode. I have to Obfuscate my Android Project. I have tried below links but none worked for me.

1.proguardRelease FAILED when compiling Apk with assembleRelease in Android Studio

  1. Proguard minifyEnabled true for debug builds, not working on pre-Lollipop

Below is app build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId 'XX.XX.XXX'
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 9
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    sourceSets.main {
        jni.srcDirs = [] //disable automatic ndk-build call
        jniLibs.srcDir 'src/main/libs' //integrate your libs from libs instead of jniLibs
    }
    dexOptions {
        javaMaxHeapSize "4g" //specify the heap size for the dex process
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }


    }
    productFlavors {
    }
    lintOptions {
        checkReleaseBuilds false
    }
    packagingOptions {
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'

    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    //    compile files('libs/maflogonimo-1.210.3.jar')
    compile project(':android-logging-log4j-1.0.3')
    compile project(':log4j-1.2.17')
    compile files('libs/gson-2.6.2.jar')
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.google.android.gms:play-services-location:10.0.1'
    compile 'com.google.android.gms:play-services-auth:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.esri.arcgis.android:arcgis-android:10.2.8-1'
    //GIS

    compile(name:'ClientHubSLL-3.16.1', ext:'aar')
    compile(name:'ClientLog-3.16.1', ext:'aar')
    compile(name:'Common-3.16.1', ext:'aar')
    compile(name:'Connectivity-3.16.1', ext:'aar')
    compile(name:'CoreServices-3.16.1', ext:'aar')
    compile(name:'DataVaultLib-3.16.1', ext:'aar')
    compile(name:'E2ETrace-3.16.1', ext:'aar')
    compile(name:'HttpConvAuthFlows-3.16.1', ext:'aar')
    compile(name:'HttpConversation-3.16.1', ext:'aar')
    compile(name:'MAFLogger-3.16.1', ext:'aar')
    compile(name:'MAFLogonCore-3.16.1', ext:'aar')
    compile(name:'ODataAPI-3.16.1', ext:'aar')
    compile(name:'ODataOnline-3.16.1', ext:'aar')
    compile(name:'Request-3.16.1', ext:'aar')
    compile(name:'SupportabilityFacade-3.16.1', ext:'aar')

    compile(name:'MAFCalendar-3.16.1', ext:'aar')
    compile(name:'MAFLocaleAwareControls-3.16.1', ext:'aar')
    compile(name:'MAFLogViewer-3.16.1', ext:'aar')
    compile(name:'MAFSettingScreen-3.16.1', ext:'aar')
    compile(name:'MAFTreeView-3.16.1', ext:'aar')
    compile(name:'MAFUIComponents-3.16.1', ext:'aar')
    compile(name:'XscriptParser-3.16.1', ext:'aar')
    compile(name:'MAFLogonUI-3.16.1', ext:'aar')
    compile(name:'MobilePlace-3.16.1', ext:'aar')

}

apply plugin: 'com.google.gms.google-services'

Below is proguard-rules.pro file

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keepattributes Exceptions, Signature, InnerClasses



-keep class org.javarosa.** { *; }
-keep class com.sap.** { *; }

-dontwarn com.google.**
-dontwarn org.apache.**
-dontwarn com.sap.**
-dontwarn au.com.bytecode.**
-dontwarn org.joda.**
-dontwarn android.content.**
-dontwarn android.graphics.**
-dontwarn android.util.**
-dontwarn android.view.**

Warnings after running in Debug mode

Warning:jcifs.http.NetworkExplorer: can't find superclass or interface javax.servlet.http.HttpServlet
Warning:jcifs.http.NtlmHttpFilter: can't find superclass or interface javax.servlet.Filter
Warning:jcifs.http.NtlmHttpServletRequest: can't find superclass or interface javax.servlet.http.HttpServletRequestWrapper
Warning:jcifs.http.NtlmServlet: can't find superclass or interface javax.servlet.http.HttpServlet
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServlet
Warning:jcifs.http.NetworkExplorer: can't find referenced method 'java.util.Enumeration getInitParameterNames()' in program class jcifs.http.NetworkExplorer
Warning:jcifs.http.NetworkExplorer: can't find referenced method 'java.lang.String getInitParameter(java.lang.String)' in program class jcifs.http.NetworkExplorer
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.ServletException
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.ServletOutputStream....

    Warning: there were 141 unresolved references to classes or interfaces.
             You may need to add missing library jars or update their versions.
             If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options.
             (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
    Warning: there were 2 unresolved references to program class members.
             Your input classes appear to be inconsistent.
             You may need to recompile the code.
             (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
    Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
    :app:transformClassesAndResourcesWithProguardForDebug FAILED

Please help me with this. Thanks in advance.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Naveen
  • 481
  • 2
  • 6
  • 23
  • Can you provide the warnings as well – Ankit Dubey Aug 01 '18 at 09:29
  • @Ankit, Sure, I will update the Question.I have edited, I cannot post the complete log but I have added some warnings.Hope you will understand. please check. Warning is related to "javax.servlet.http.**" – Naveen Aug 01 '18 at 09:33
  • @Ankit, I have edited, I cannot post the complete log but I have added some warnings.Hope you will understand. please check. Warning is related to "javax.servlet.http.**" – Naveen Aug 01 '18 at 09:39
  • It seems proguard is removing the classes whil obfuscation, In general you have to fix each of these warnings by adding proguard rules. I googled and find out this rule -dontwarn org.jboss.netty.** . BTW why are using jboss library in android app. – Ankit Dubey Aug 01 '18 at 09:42
  • Thank you for your response @AnkitDubey, I am not using jboss library.If I add " -dontwarn org.jboss.netty.** " this in proguard will it work ? – Naveen Aug 01 '18 at 09:45
  • the warnings will come only when you are using them :), it seems you have lots of dependency aar files. compile(name:'ClientHubSLL-3.16.1', ext:'aar') compile(name:'ClientLog-3.16.1', ext:'aar') compile(name:'Common-3.16.1', ext:'aar') compile(name:'Connectivity-3.16.1', ext:'aar') compile(name:'CoreServices-3.16.1', ext:'aar') compile(name:'DataVaultLib-3.16.1', ext:'aar') . It seems one of them are using these libraries. – Ankit Dubey Aug 01 '18 at 09:47
  • I have added this " -dontwarn org.jboss.netty.** " in proguard file but it didn't worked out.I am trying this from past 2 days but no luck.Any way to resolve this Issue Ankit ? – Naveen Aug 01 '18 at 09:50
  • the only way is to google each warning and find out corresponding rules for either keep or dont warn and apply them. You will have to investigate the dependency aar , they might be using these library internally. – Ankit Dubey Aug 01 '18 at 10:00
  • The main Issue is with " javax.servlet.** " Ankit. – Naveen Aug 01 '18 at 10:03
  • As i said earlier, you need to investigate your dependency aar files, – Ankit Dubey Aug 01 '18 at 10:04
  • Is there any chance of adding each library in proguard file, so that the issue may resolve ? – Naveen Aug 01 '18 at 10:08
  • @Naveen I am having the exact same issue, Do you remember how you solved this? – sachadso May 29 '20 at 11:24

0 Answers0