minifyEnabled - true 在调试模式下不起作用

Posted

技术标签:

【中文标题】minifyEnabled - true 在调试模式下不起作用【英文标题】:minifyEnabled - true is not working in debug mode 【发布时间】:2019-01-07 10:13:53 【问题描述】:

minifyEnabled - true 在调试模式下不适用于 android。我必须混淆我的 Android 项目。我尝试了以下链接,但没有一个对我有用。

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

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

以下是我的应用程序构建 gradle 文件

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'

例外

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..................

请帮助我。在此先感谢。

【问题讨论】:

从构建或事件日志面板发布您的错误日志。 @Khemraj,感谢您的回复,我正在重新构建。会尽快更新您。 @Khemraj,错误:任务':app:transformClassesAndResourcesWithProguardForDebug'的执行失败。 > java.io.IOException: 请先纠正上述警告。 这是默认错误,它带有一些特定的错误。在已编辑的问题中发布您的完整错误日志。 我已编辑,无法发布完整的日志,但我添加了一些警告。希望您能理解。请检查@Khemraj 【参考方案1】:

请尝试一下,并为您正在使用的库使用适当的 proguard 规则。 Proguard 会混淆甚至来自第三方库的每个类,除非您为这些类设置特定规则。

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

常用proguard sn-ps: https://github.com/krschultz/android-proguard-snippets

【讨论】:

感谢您的回复。我应该在应用程序 build.gradle 中使用“proGuard false”还是“debuggable false”? minifyEnabled true debuggable false - 不工作【参考方案2】:

你说你得到了以下异常:

错误:任务“:app:transformClassesAndResourcesWithProguardForDebug”执行失败。 > java.io.IOException: 请先更正上述警告。

Proguard 和 Dexguard 会混淆代码并显示大量警告,但这并不意味着您的应用无法运行。问题在于,使用默认配置,编译将在每次警告时停止。然而,大多数时候忽略这些警告是一个合理的选择。要尝试此操作,请使用以下命令:

-ignorewarnings 指定打印有关未解决的引用和其他重要问题的任何警告,但继续处理 任何情况。忽视警告可能很危险。例如,如果 确实需要未解析的类或类成员 处理,处理后的代码将无法正常运行。只使用 如果您知道自己在做什么,请选择此选项!

或者如果你想单独指定类或包(更好的选择):

-dontwarn [class_filter] 指定根本不警告未解决的引用和其他重要问题。可选过滤器是一个正则表达式; DexGuard 不会打印有关名称匹配的类的警告。忽视警告可能很危险。例如,如果确实需要处理未解析的类或类成员,则处理后的代码将无法正常运行。仅当您知道自己在做什么时才使用此选项!

这不是最佳和/或最终解决方案。警告可能意味着您的应用正在混淆应该保留的类,但至少这样您可以运行并稍后查看错误(例如 ClassNotFoundException)。

如果这不能解决您的问题,请尝试通过添加以下命令来获取错误的堆栈跟踪:

-详细 指定在处理期间写出更多信息。如果程序因异常而终止,此选项将打印出整个堆栈跟踪,而不仅仅是异常消息。

【讨论】:

嗨 Styehard,感谢您的回复,当我在 Debug 或 Release 中构建项目时,它无法正常工作,给出我在 Exception 中提到的上述错误。请您查看 Exception 并提供帮助请告诉我。在此先感谢 添加行 -ignorewarnings 并告诉我你是否仍然得到异常。您在示例中添加的“异常”实际上并没有显示错误,只是像我之前解释的那样在 proguard 应用程序中正常显示的警告。 是的,仍然出现异常。 请添加 -verbose 并尝试获取确切的错误消息。使用 -ignorewarnings 它应该让你运行你的应用程序,然后在运行时得到错误 添加 -igonrewarnings, -verbose 后出现问题 -----Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(android.support.design.widget.ai) that doesn't带有一个错误:关联的 EnclosureMethod 属性。这个类可能是由不针对现代 .class 文件格式的错误:编译器生成的。推荐的错误:解决方案是从源代码重新编译类,使用最新的编译器错误:并且不指定任何“-target”类型选项。忽视的后果【参考方案3】:

将此添加到您的proguard-rules.pro

-dontwarn javax.naming.**
-dontwarn javax.servlet.**
-dontwarn org.slf4j.**

【讨论】:

以上是关于minifyEnabled - true 在调试模式下不起作用的主要内容,如果未能解决你的问题,请参考以下文章

Proguard minifyEnabled true 用于调试构建,不适用于预棒棒糖

Android minifyEnabled true for firebase

buildTypes 调试问题中的 gradle minifyEnabled false

NotSerializableException: kotlin.UNINITIALIZED_VALUE 设置 minifyEnabled 后为 true

在 minifyEnabled true 后启动应用程序时出现 NumberFormatException

当 minifyEnabled 为 true 时,膨胀类 androidx.fragment.app.FragmentContainerView 时出错