-1

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

2.Proguard minifyEnabled true for debug build, not working on pre-Lollipop

Below is my application build gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId 'XX.XXX'
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 9
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    sourceSets.main {
        jni.srcDirs = [] 
        jniLibs.srcDir 'src/main/libs' 
    }
    dexOptions {
        javaMaxHeapSize "4g" 
    }
    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 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.viewpagerindicator:library:2.4.1@aar'
    //compile files('libs/hellocharts-library-1.5.8.jar')
    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'

Exception

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:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpSession
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpSession
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServlet
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:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpSession
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
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:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NetworkExplorer: can't find referenced class javax.servlet.http.HttpSession
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.FilterConfig
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.FilterChain
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.http.HttpSession
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.http.HttpServletRequest
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.http.HttpServletResponse
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.Filter
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.ServletException
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.FilterConfig
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.FilterChain
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.http.HttpSession
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.FilterConfig
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.ServletRequest
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.ServletResponse
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.FilterChain
Warning:jcifs.http.NtlmHttpFilter: can't find referenced class javax.servlet.ServletReq..................

Please help me on this.Thanks in advance.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
Naveen
  • 481
  • 2
  • 6
  • 23

3 Answers3

0

Please, try this and use appropriate proguard rules for the libraries you are using. Proguard will obfuscate every class even from third party libraries, unless you set specific rules for those.

debug {
        minifyEnabled true
        debuggable false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }

Common proguard snippets: https://github.com/krschultz/android-proguard-snippets

minhazur
  • 4,928
  • 3
  • 25
  • 27
0

You say you are getting the following exception:

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForDebug'. > java.io.IOException: Please correct the above warnings first.

Proguard and Dexguard will obfuscate code and show a lot of warnings but that doesn't mean your app wont work. The problem is that with the default config the compilation will stop at every warning. However, most of the time ignoring these warnings is a reasonable option . To try this use the following command:

-ignorewarnings Specifies to print any warnings about unresolved references and other important problems, but to continue processing in any case. Ignoring warnings can be dangerous. For instance, if the unresolved classes or class members are indeed required for processing, the processed code will not function properly. Only use this option if you know what you're doing!

Or this if you want to specify classes or packages individually(better option):

-dontwarn [class_filter] Specifies not to warn about unresolved references and other important problems at all. The optional filter is a regular expression; DexGuard doesn't print warnings about classes with matching names. Ignoring warnings can be dangerous. For instance, if the unresolved classes or class members are indeed required for processing, the processed code will not function properly. Only use this option if you know what you're doing!

This is not the best and/or final solution. Warnings can mean that your app is obfuscating classes that should be kept but at least with this you can run and see the errors later (Like for example ClassNotFoundException).

If this does not solve your problem try to get the stacktrace of the error with the following command added:

-verbose Specifies to write out some more information during processing. If the program terminates with an exception, this option will print out the entire stack trace, instead of just the exception message.

Styehard
  • 11
  • 2
  • Hi Styehard, thanks for your response, When ever I build the project in Debug or Release it is not working, giving the above errors which I have mentioned in Exception.may you please look into Exception and help me on this please.Thanks in advance – Naveen Jul 31 '18 at 09:43
  • Add the line -ignorewarnings and tell me if u still get the exception please. The "Exception" you have put in your example doesnt actually show the error, just the warnings which are something normal in proguard apps as I explained before. – Styehard Jul 31 '18 at 10:16
  • Yes, still getting the exception. – Naveen Jul 31 '18 at 10:16
  • Add -verbose and try to get the exact error message please. With -ignorewarnings it should let you run your app and then get the error on runtime – Styehard Jul 31 '18 at 10:20
  • Issue after adding -igonrewarnings, -verbose -----Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(android.support.design.widget.ai) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring – Naveen Jul 31 '18 at 10:41
  • Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. – Naveen Jul 31 '18 at 10:41
  • the command -verbose makes the compilation give the whole error messages but should not create any new ones. Try to delete "-ignorewarnings" and just with "-verbose" check what kind of errors it gives about the warnings. – Styehard Jul 31 '18 at 11:16
  • As for the error you provided there are a lot of "Error:" that seems to be out of place in the text. Strange.. Are you using an updated SDK and Android Studio version? – Styehard Jul 31 '18 at 11:18
  • Hi Styehard, I am using updated SDK (Oreo), AndroidStudio is 1.5.1. – Naveen Aug 01 '18 at 06:09
0

Add this to your proguard-rules.pro

-dontwarn javax.naming.**
-dontwarn javax.servlet.**
-dontwarn org.slf4j.**
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212