2013-01-15 2 views
0

Android에서 다음과 같은 설정을 사용합니다.Android Proguard에서 Java SE 라이브러리 제외

-dontpreverify 

# Hold onto the mapping.text file, it can be used to unobfuscate stack traces in the developer console using the retrace tool 
-printmapping mapping.txt 

# Keep line numbers so they appear in the stack trace of the develeper console 
-keepattributes SourceFile,LineNumberTable 

# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. 
-optimizations !code/simplification/arithmetic 

# Activities, services and broadcast receivers are specified in the manifest file so they won't be automatically included 
-keep public class * extends android.app.Activity 
-keep public class * extends android.app.Application 
-keep public class * extends android.app.Service 
-keep public class * extends android.content.BroadcastReceiver 
-keep public class * extends android.content.ContentProvider 

# Custom view components might be accessed from your layout files 
-keep public class * extends android.view.View { 
    public <init>(android.content.Context); 
    public <init>(android.content.Context, android.util.AttributeSet); 
    public <init>(android.content.Context, android.util.AttributeSet, int); 
    public void set*(...); 
} 

# event handlers can be specified in the layout files e.g. android:onClick="nextButton_onClick", I borrowed this method name notation from .NET 
-keepclassmembers class * extends android.app.Activity { 
    public void *_*(android.view.View); 
} 

# Parcelable implementations are accessed by introspection 
-keepclassmembers class * implements android.os.Parcelable { 
    static android.os.Parcelable$Creator CREATOR; 
} 

# You might want to keep your annotations 
-keepattributes *Annotation* 

# I use Google Guava in my app 
# see http://code.google.com/p/guava-libraries/wiki/UsingProGuardWithGuava 
-libraryjars libs/google/jsr305-1.3.9.jar;libs/pinyin4j/pinyin4j-2.5.0.jar 
-dontwarn sun.misc.Unsafe 

-keepclasseswithmembers class com.google.common.base.internal.Finalizer{ 
    <methods>; 
} 

내 라이브러리 중 일부는 직접 자바 SE에서 수입 내가 난독에서 제외 할 수 있습니까

(JApplet에 예를 들면 포함)? 참고, pinyin4j-2.5.0.jar 라이브러리에 -libraryjars이 있습니다. 나는 그것이 프로 가드에게 "이봐, 이건 도서관이다. 아무것도하지 마라."라고 말하는 방법이라고 생각했습니다. 하지만 프로 가드가 아직 처리하려고 시도하는 것 같습니다. pinyin4j-2.5.0.jar

다음 오류가 발생합니다.

Note: there were 125 duplicate class definitions. 
Warning: demo.Pinyin4jAppletDemo: can't find superclass or interface javax.swing.JApplet 
Warning: demo.Pinyin4jAppletDemo$1: can't find superclass or interface java.awt.event.WindowAdapter 
Warning: demo.Pinyin4jAppletDemo$2: can't find superclass or interface java.awt.event.ActionListener 
Warning: demo.Pinyin4jAppletDemo$3: can't find superclass or interface java.awt.event.ActionListener 
Warning: org.jasypt.encryption.pbe.PBEBigDecimalCleanablePasswordEncryptor: can't find superclass or interface org.jasypt.encryption.pbe.PBEBigDecimalEncryptor 
Warning: org.jasypt.encryption.pbe.PBEBigIntegerCleanablePasswordEncryptor: can't find superclass or interface org.jasypt.encryption.pbe.PBEBigIntegerEncryptor 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyDescriptor 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyDescriptor 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditor 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditor 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditor 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditorManager 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyDescriptor 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.IntrospectionException 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyEditor 
Warning: au.com.bytecode.opencsv.bean.CsvToBean: can't find referenced class java.beans.PropertyDescriptor 
... 
... 
Warning: org.jasypt.normalization.Normalizer: can't find referenced class com.ibm.icu.text.Normalizer$Mode 
     You should check if you need to specify additional program jars. 
Warning: there were 333 unresolved references to classes or interfaces. 
     You may need to specify additional library jars (using '-libraryjars'). 
Warning: there were 6 unresolved references to program class members. 
     Your input classes appear to be inconsistent. 
     You may need to recompile them and try again. 
     Alternatively, you may have to specify the option 
     '-dontskipnonpubliclibraryclassmembers'. 
Error: Please correct the above warnings first. 

당신의 일부는 (애플릿, 스윙처럼 ...) 안드로이드에서 사용할 수 없습니다 자바 SE 유일한 방법을 포함하는 라이브러리 항아리에 대한 것을 언급 할 수있다. Nope. 실제로 Java SE가 아닌 메소드를 사용하는 한 완벽하게 실행됩니다.

전체 오류 로그 여기에서 다운로드 할 수 있습니다 https://www.dropbox.com/s/dns62f7gp6unusg/error-log.txt

+0

안드로이드는 이러한 클래스를 가지고 있지 않기 때문에 당신은 당신의 안드로이드 응용 프로그램에서 어쨌든 사용할 수 없습니다. – CommonsWare

+0

나는이 라이브러리를 라이브러리로 포함한다고 가정 할 것이므로 그 라이브러리를'-libraryjars'에 추가 할 필요가있다.하지만 실제로 여기서 무엇을 하려는지는 모른다. 이 클래스는 안드로이드에서 작동하지 않습니다. – njzk2

+0

모두는 도서관입니다. 사실, proguard를 소개하기 전에 (예 : pinyin4j-2.5.0.jar -> demo.Pinyin4jAppletDemo) 완벽하게 작동합니다. 그들이 작동하는 이유는 라이브러리에서 Java SE 전용 메소드를 사용하지 않는 메소드 만 사용하기 때문입니다. 이제 문제는 ProGuard가 내 모든 lib jar를 처리하고자하는 것입니다. –

답변

5

이러한 Java SE 클래스가 사용되지 않는다고 확신하는 경우 실제로는 경고를 무시할 수 있습니다 (직접 답변 에서처럼).쉬운 방법이를 지정하려면 :

1

예를 자바 런타임 (rt.jar을)를 유지하기 위해

<libraryjar file="${java.home}/lib/rt.jar" /> 

당신의 라인

-libraryjars libs/google/jsr305-1.3.9.jar;libs/pinyin4j/pinyin4j-2.5.0.jar 

는 것 같다 완전하지 않은. 업데이트 하지만 필요한 클래스가 안드로이드에 없기 때문에 이러한 경고를 무시해야합니다. 그러나 일반적으로 난독 화 경고를 무시하지 않고 모든 경고를 무시했기 때문에 파일에 obfuscation.map을 사용하여 심각한 버그가있었습니다. 나는 단지

-dontwarn sun.misc.Unsafe 
-dontwarn com.google.common.collect.MinMaxPriorityQueue 
-dontwarn javax.swing.** 
-dontwarn java.awt.** 
-dontwarn org.jasypt.encryption.pbe.** 
-dontwarn java.beans.** 
-dontwarn org.joda.time.** 
-dontwarn com.google.android.gms.** 
-dontwarn org.w3c.dom.bootstrap.** 
-dontwarn com.ibm.icu.text.** 
-dontwarn demo.** 

하여 오류를 방지

+0

-libraryjars에 이미'libs/pinyin4j/pinyin4j-2.5.0.jar'가 포함되어 있지만, 여전히 demo.Pinyin4jAppletDemo에 대한 오류가 있습니다 (pinyin4j-2.5.0.jar에 있음) –

+0

런타임도. android.jar? 나는 안드로이드를 잘 모른다. – AlexWien

+0

실제로, 나는 그들의 문서를 읽은 후에 -libraryjars를 어떻게 사용하는지 이해하지 못합니다. 우리는 프로 가드에게 "그들은 도서관이다"라고 말한다. 좋아요, 도서관 일 경우,이 도서관에서 무슨 보호자가 할 것입니까? –

0

여기에 나는 아직도 "난독 생성 한 후"의 충돌을 경험으로

-optimizationpasses 1 
-dontusemixedcaseclassnames 
-dontskipnonpubliclibraryclasses 
-dontpreverify 
-verbose 
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 

#-dontobfuscate 

-dontwarn sun.misc.Unsafe 
-dontwarn com.google.common.collect.MinMaxPriorityQueue 
-dontwarn javax.swing.** 
-dontwarn java.awt.** 
-dontwarn org.jasypt.encryption.pbe.** 
-dontwarn java.beans.** 
-dontwarn org.joda.time.** 
-dontwarn com.google.android.gms.** 
-dontwarn org.w3c.dom.bootstrap.** 
-dontwarn com.ibm.icu.text.** 
-dontwarn demo.** 

# Hold onto the mapping.text file, it can be used to unobfuscate stack traces in the developer console using the retrace tool 
-printmapping mapping.txt 

# Keep line numbers so they appear in the stack trace of the develeper console 
-keepattributes *Annotation*,SourceFile,LineNumberTable 

-keep public class * extends android.app.Activity 
-keep public class * extends android.app.Application 
-keep public class * extends android.app.Service 
-keep public class * extends android.content.BroadcastReceiver 
-keep public class * extends android.content.ContentProvider 
-keep public class * extends android.app.backup.BackupAgentHelper 
-keep public class * extends android.preference.Preference 
-keep public class com.android.vending.licensing.ILicensingService 

-keep class android.support.v4.app.** { *; } 
-keep interface android.support.v4.app.** { *; } 
-keep class com.actionbarsherlock.** { *; } 
-keep interface com.actionbarsherlock.** { *; } 

# https://sourceforge.net/p/proguard/discussion/182456/thread/e4d73acf 
-keep class org.codehaus.** { *; } 

-assumenosideeffects class android.util.Log { 
    public static int d(...); 
    public static int i(...); 
    public static int e(...); 
    public static int v(...); 
} 

-keepclasseswithmembernames class * { 
    native <methods>; 
} 

-keepclasseswithmembers class * { 
    public <init>(android.content.Context, android.util.AttributeSet); 
} 

-keepclasseswithmembers class * { 
    public <init>(android.content.Context, android.util.AttributeSet, int); 
} 

-keepclassmembers class * extends android.app.Activity { 
    public void *(android.view.View); 
} 

-keepclassmembers enum * { 
    public static **[] values(); 
    public static ** valueOf(java.lang.String); 
} 

-keep class * implements android.os.Parcelable { 
    public static final android.os.Parcelable$Creator *; 
} 

-assumenosideeffects class android.util.Log { 
    public static *** d(...); 
    public static *** v(...); 
    public static *** i(...); 
} 

# I use Google Guava in my app 
# see http://code.google.com/p/guava-libraries/wiki/UsingProGuardWithGuava 
-libraryjars libs/google/jsr305-1.3.9.jar 

-keepclasseswithmembers class com.google.common.base.internal.Finalizer{ 
    <methods>; 
} 

아직 상자에서 완전히 작동하지 않습니다 전체 난독 구성입니다 APK.

코드가 혼란 스럽기 때문에 내가 왜 충돌하는지 알기가 꽤 어렵습니다.

구체적으로 dontobfuscate이라면 생성하는 동안 또 다른 문제가 발생할 것입니다. 추가 정보없이 "Dalvik 형식으로 변환이 실패하여 오류 1로 실패했습니다"라는 메시지가 나타납니다. 그러나 그것은 다른 문제의 또 다른 집합입니다.