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..................
请为此提供帮助。谢谢。
答案 0 :(得分:0)
请尝试此操作,并对所使用的库使用适当的proguard规则。 Proguard甚至会混淆第三方库中的每个类,除非您为它们设置了特定的规则。
debug {
minifyEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
常见的proguard片段: https://github.com/krschultz/android-proguard-snippets
答案 1 :(得分:0)
您说您收到以下异常:
错误:任务':app:transformClassesAndResourcesWithProguardForDebug'的执行失败。 > java.io.IOException:请首先更正以上警告。
Proguard和Dexguard会混淆代码并显示很多警告,但这并不意味着您的应用程序将无法运行。问题在于,使用默认配置时,编译将在每次警告时停止。但是,大多数时候忽略这些警告是一个合理的选择。要尝试此操作,请使用以下命令:
-ignorewarnings 指定打印有关未解决引用和其他重要问题的任何警告,但继续在 任何情况。忽视警告可能很危险。例如,如果 确实需要未解决的班级或班级成员 处理后,处理后的代码将无法正常运行。只用 如果您知道自己在做什么,请选择此选项!
或者如果您想单独指定类或包(更好的选择),请执行以下操作:
-dontwarn [class_filter] 指定根本不警告尚未解决的引用和其他重要问题。可选过滤器是一个正则表达式; DexGuard不会打印有关名称匹配的类的警告。忽视警告可能很危险。例如,如果确实需要未解析的类或类成员进行处理,则处理后的代码将无法正常运行。仅当您知道自己在做什么时才使用此选项!
这不是最佳和/或最终解决方案。警告可能意味着您的应用混淆了应该保留的类,但至少与此相关,您可以稍后运行并查看错误(例如ClassNotFoundException)。
如果这不能解决您的问题,请尝试添加以下命令来获取错误的堆栈跟踪:
-详细 指定在处理期间写出更多信息。如果程序因异常终止,则此选项将打印出整个堆栈跟踪,而不仅仅是异常消息。
答案 2 :(得分:0)
将此添加到您的proguard-rules.pro
-dontwarn javax.naming.**
-dontwarn javax.servlet.**
-dontwarn org.slf4j.**