2014-12-29 3 views
8

내 애플리케이션의 APK 생성에 문제가 있습니다.ProGuard minification을 사용하는 경우 Android Studio에서 APK를 만들 수 없습니다.

내가 디버깅/응용 프로그램을 실행하면 정상적으로 작동합니다. 내가 해당 APK를 생성 할 때, 안드로이드 스튜디오 나에게 경고를 많이하고 하나의 오류를 제공합니다 :

Note: there were 159 duplicate class definitions. 
    (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass) 
Warning:com.thoughtworks.xstream.converters.reflection.CGLIBEnhancedConverter$ReverseEngineeredCallbackFilter: can't find superclass or interface net.sf.cglib.proxy.CallbackFilter 
Warning:org.apache.harmony.awt.datatransfer.DataProxy: can't find superclass or interface java.awt.datatransfer.Transferable 
Warning:org.apache.harmony.awt.datatransfer.NativeClipboard: can't find superclass or interface java.awt.datatransfer.Clipboard 
Warning:library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser 
Warning:library class org.apache.http.auth.AuthenticationException extends or implements program class org.apache.http.ProtocolException 
[...] 
Warning:library class org.apache.http.impl.conn.LoggingSessionOutputBuffer extends or implements program class org.apache.http.io.SessionOutputBuffer 
Warning:com.itextpdf.testutils.ITextTest: can't find referenced class javax.management.OperationsException 
Warning:com.itextpdf.text.pdf.BarcodeCodabar: can't find referenced class java.awt.Color 
[...] 
Warning:com.itextpdf.text.pdf.security.MakeXmlSignature: can't find referenced class javax.xml.crypto.dsig.spec.C14NMethodParameterSpec 
[...] 
Warning:com.sun.mail.handlers.image_gif: can't find referenced class java.awt.datatransfer.DataFlavor 
[...] 
Warning:com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl 
[...] 
Warning:com.thoughtworks.xstream.converters.extended.ColorConverter: can't find referenced class java.awt.Color 
[...] 
Warning:org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit 
[...] 
Warning:org.spongycastle.jce.provider.X509LDAPCertStoreSpi: can't find referenced class javax.naming.directory.InitialDirContext 
[...] 
Warning:library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser 
[...] 
Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpResponse 
[...] 
Warning:library class org.xmlpull.v1.XmlPullParserFactory depends on program class org.xmlpull.v1.XmlPullParser 
Warning:there were 1077 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 141 instances of library classes depending on program classes. 
     You must avoid such dependencies, since the program classes will 
     be processed, while the library classes will remain unchanged. 
     (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency) 
Warning:there were 5 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) 
:vet:proguardInternalRelease FAILED 
Error:Execution failed for task ':PROJECTNAME:proguardInternalRelease'. 
> java.io.IOException: Please correct the above warnings first. 
Information:BUILD FAILED 
Information:Total time: 13.878 secs 
Information:1 error 
Information:679 warnings 
Information:See complete output in console 

프로젝트는 settings.gradle이 같은 외부 프로젝트로 가져 오기, 라이브러리 프로젝트에 의해 형성된다 :

include ':library' 
project(':library').projectDir = new File(settingsDir, '../Library/library') 

모든 종속성이 있습니다. 그래서 APK 컴파일 할 수 있습니다 어떻게 그것을 해결합니까 라이브러리의

build.gradle

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     minSdkVersion 15 
     targetSdkVersion 21 
     multiDexEnabled true 
    } 

    packagingOptions { 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
    } 

} 

dependencies { 
    compile 'com.google.android.gms:play-services:+' 
    compile 'com.android.support:support-v13:21.0.+' 
    compile 'com.android.support:multidex:1.0.0' 
    compile('ch.acra:acra:4.5.0') { 
     exclude group: 'org.json' 
    } 
    compile 'org.apache.httpcomponents:httpcore:4.3' 
    compile('org.apache.httpcomponents:httpmime:4.3.1') { 
     exclude group: 'org.apache.httpcomponents', module: 'httpcore' 
     exclude group: 'org.apache.httpcomponents', module: 'httpclient' 
    } 
    compile('javax.mail:mail:1.4.7') { 
     exclude module: 'activation' 
    } 
    compile 'com.madgag.spongycastle:pkix:1.50.0.0' 
    compile 'org.ccil.cowan.tagsoup:tagsoup:1.2.1' 
    compile ('com.itextpdf.tool:xmlworker:5.5.1'){ 
     exclude module: 'itextpdf' 
    } 
    compile('com.thoughtworks.xstream:xstream:1.4.4') { 
     exclude group: 'xmlpull', module: 'xmlpull' 
    } 
    compile 'com.google.zxing:core:3.0.1' 
    compile files('libs/activation.jar') 
    compile files('libs/additionnal.jar') 
    compile files('libs/miniTemplator.jar') 
    compile files('libs/itextg-5.5.1.jar') 
} 

하고 프로젝트 build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "my.package.name" 
     minSdkVersion 15 
     targetSdkVersion 21 
     multiDexEnabled true 
    } 

    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

    productFlavors { 
     def BOOLEAN = "boolean" 
     def TRUE = "true" 
     def FALSE = "false" 
     def A_FIELD= "A_FIELD" 

     internal { 
      buildConfigField BOOLEAN, A_FIELD, FALSE 
     } 

     official { 
      buildConfigField BOOLEAN, A_FIELD, TRUE 
     } 
    } 


    packagingOptions { 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
    } 
} 

dependencies { 
    compile project(':library') 
} 

afterEvaluate { 
    tasks.matching { 
     it.name.startsWith('dex') 
    }.each { dx -> 
     if (dx.additionalParameters == null) { 
      dx.additionalParameters = [] 
     } 
     dx.additionalParameters += '--multi-dex' 
    } 
} 

입니까?

EDIT : 내 proguard-rules.pro에 -dontwarn 옵션을 많이 추가 한 후에 어쨌든 오류가 발생하고 이러한 경고를 해결할 수 없습니다 (Here). 이러한 경고는 없습니다. .) :

Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced method 'ASN1Integer(int)' in program class org.spongycastle.asn1.ASN1Integer 
Warning:com.sun.activation.viewers.ImageViewer: can't find referenced method 'java.awt.Component add(java.awt.Component)' in program class com.sun.activation.viewers.ImageViewer 
Warning:com.sun.activation.viewers.ImageViewer: can't find referenced method 'java.awt.Toolkit getToolkit()' in program class com.sun.activation.viewers.ImageViewer 
Warning:com.sun.activation.viewers.ImageViewer: can't find referenced method 'void invalidate()' in program class com.sun.activation.viewers.ImageViewer 
Warning:com.sun.activation.viewers.ImageViewer: can't find referenced method 'void validate()' in program class com.sun.activation.viewers.ImageViewer 
Warning:com.sun.activation.viewers.ImageViewer: can't find referenced method 'void doLayout()' in program class com.sun.activation.viewers.ImageViewer 
Warning:com.sun.activation.viewers.ImageViewerCanvas: can't find referenced method 'void invalidate()' in program class com.sun.activation.viewers.ImageViewerCanvas 
Warning:com.sun.activation.viewers.ImageViewerCanvas: can't find referenced method 'void repaint()' in program class com.sun.activation.viewers.ImageViewerCanvas 
Warning:com.sun.activation.viewers.TextEditor: can't find referenced method 'void setLayout(java.awt.LayoutManager)' in program class com.sun.activation.viewers.TextEditor 
Warning:com.sun.activation.viewers.TextEditor: can't find referenced method 'void invalidate()' in program class com.sun.activation.viewers.TextEditor 
Warning:com.sun.activation.viewers.TextViewer: can't find referenced method 'void setLayout(java.awt.LayoutManager)' in program class com.sun.activation.viewers.TextViewer 
Warning:com.sun.activation.viewers.TextViewer: can't find referenced method 'java.awt.Component add(java.awt.Component)' in program class com.sun.activation.viewers.TextViewer 
Warning:com.sun.activation.viewers.TextViewer: can't find referenced method 'void invalidate()' in program class com.sun.activation.viewers.TextViewer 
Warning:javax.activation.ActivationDataFlavor: can't find referenced method 'boolean isMimeTypeEqual(java.awt.datatransfer.DataFlavor)' in program class javax.activation.ActivationDataFlavor 
Warning:there were 14 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) 
:vet:proguardInternalRelease FAILED 
Error:Execution failed for task ':vet:proguardInternalRelease'. 
> java.io.IOException: Please correct the above warnings first. 
+0

http://proguard.sourceforge.net/manual/troubleshooting.html에 대한 경고/오류 메시지를 확인하십시오. –

+0

귀하의 링크를 따라 proguard-rules.pro에서 -dontwarn 옵션을 많이 추가했지만 경고가 없더라도 어쨌든 오류가 발생했습니다 ... 질문을 업데이트했습니다 ... – Garro88

답변

6

이들은 청소하기가 어렵습니다. 더 나은 라이브러리는 현재 라이브러리 패키지에 설정을 포함하지만 더 오래된 (또는 lazier) 것들은 아직 없습니다. 여기 프로세스 수행되어 개발

동안 : 새 라이브러리가 포함되어 있습니다 때마다

  • 가 자신의 제안 ProGuard에서 설정에 해당 설명서를 확인해야합니다. (이것으로 부지런히 사용하면 나중에 많은 혼란과 파기를 피할 수 있습니다.)
  • 라이브러리 작성자가 AAR 패키지를 제공하는 경우 (예 : 전체 AAR을 얻기 위해 gradle 종속 라인의 끝에 '@aar' 더 단순한 JAR 대신) 자동으로 선택 될 수있는 ProGuard 예외가 거기에 포함되어있을 수도 있습니다. (그러나 내 경험상 대부분의 저자는 여전히이 추가 단계를 취하지 않고있다.)
  • 동적 인트로 스코프가 필요한 사용자 정의 코드에 새로운 네임 스페이스/클래스가 추가 될 때마다 (예 : 의존성 주입 컨테이너 또는 JSON 파서를 사용할 때) ProGuard는 패키지 이름에 따라 패키지를 선택하거나 한 번에 한 클래스 씩 추가하도록 설정되어 있습니다.

오류를 구축하고 점점 후 :

  • 시작 후 warning:합니다 (note: 라인 빌드를 멈추지 않을 것입니다) 접두사 error:로 시작하는 모든 라인.
  • 각 행에 언급 된 네임 스페이스를 확인하십시오. 관련 라이브러리를 찾습니다 (예 :은 아마도 New Relic 라이브러리 용입니다). 찾을 수없는 경우 Google 검색을 사용하여 네임 스페이스가 github README 또는 네임 스페이스에 포함 된 라이브러리를 식별 할 수있는 다른 것을 추적 할 수 있는지 확인하십시오.또는 Android Studio> 프로젝트> 패키지> 라이브러리 목록 (처음 표시하는 데 시간이 오래 걸림)을 확인하고 거기에있는 네임 스페이스를 추적하십시오. 바라건대 소스 코드를 사용할 수 있고 파일 헤더 주석에 라이브러리 세부 정보가 포함되기를 바랍니다.
  • 해당 라이브러리에 대한 설명서를 검색하십시오. 다행스럽게도 ProGuard의 필요한 변경 사항을 언급하기를 바랍니다.
  • 다시 작성하십시오.

모든 라이브러리 워드 프로세서에 말했다 변화,하지만 여전히 점점 경고 :

  • 시작 추가 -dontwarn 라인. 예 : -dontwarn com.newrelic.** (두 별표가 해당 네임 스페이스 아래에있는 전체 트리를 무시하도록 두지 마십시오. 별표가 하나만 있으면 네임 스페이스의 직접 자식을 무시합니다.)
  • dontwarn 문을 사용하면 컴파일 된 앱 (APK)을 테스트해야합니다! 디버그 (ProGuard가 아닌) 버전이 잘 돌아 갔음에도 불구하고 현재 충돌이 발생할 가능성이 높습니다. 사용했던 모든 라이브러리를 테스트하고, logcat 메시지를 확인하고, 맹목적으로 건너 뛰는 모든 코드 경로/클래스를 dontwarn으로 실행했는지 확인하십시오!

는 나사 그것은, 내 상사는 이미이 일을 해제 할 필요가 말했다 :

  • 안 ProGuard에서 :-(

을 어느 안드로이드 Studio에서 대화 상자 프로젝트 속성을 사용하거나 수정하려면 모듈 build.gradle 파일을 열고 android { buildTypes { release { minifyEnabled true } } }을 변경하고 거짓으로 설정하십시오.

ProGuard opt APK는 훨씬 더 커지고 코드는 난독 화되지 않습니다. 그러나 사장님이 지금 필요로하고 디버깅 할 시간이 없다면, 세계를 끝내려는 것이 아닙니다.

정말로 ProGuard를 사용해야하지만. 아마도 개발자에게 우리가 필요로하는 지루한 기술적 인 일을 할 수있는 시간을 더 많이 주도록 사장과 이야기 할 시간입니다.

관련 문제