Android 용 Eclipse에서 ProGuard 활성화
Android 용 ProGuard에 대한 새로운 문서 는 프로젝트 홈 디렉토리의 default.properties 파일에 줄을 추가한다고합니다. 그러나이 파일을 열 때 맨 위에서 읽었습니다.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
뭔가 빠졌습니까?
또한 Eclipse의 프로덕션 빌드 (예 : 완성 된 제품을 내보낼 때)에 대해서만 ProGuard를 활성화하는 방법이 있습니까?
내가 똑같은 것을 찾고 있었기 때문에 후속 조치-여기에 답변이 오래되었습니다-요즘 기본 proguard 구성은 sdk 디렉토리에 있습니다. 따라서 이것을 project.properties에 넣으면됩니다.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
프로젝트별로 수정하려면 proguard-project.txt를 만들고 행을 다음과 같이 변경하십시오.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
Android SDK (r20 이상)
project.properties에 언급 된 사전 정의 된 proguard.config를 확인하십시오.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
추가 정보 : http://proguard.sourceforge.net/manual/examples.html#androidapplication
Gradle에서 :
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
...
}
}
여기에서 계속 업데이트하는 proguard "기본"파일을 확인할 수 있습니다 : https://medium.com/code-procedure-and-rants/android-my-standard-proguard-ffeceaf65521
Android SDK (r19 이하)
default.properties에 추가 할 수 있습니다. 지금까지 문제없이 수동으로 추가했습니다.
라인을 추가하면 :
proguard.config=proguard.cfg
말했듯이 서명 된 응용 프로그램을 내보낼 때 ProGuard 만 사용합니다 (Android Tools => 서명 된 응용 프로그램 내보내기)
Android 2.3 이전의 SDK로 프로젝트를 시작하면 proguard.cfg
파일이 생성되지 않습니다 ( default.properties
2.3>과 동일).
자동 생성을 사용하려면 Android 2.3 SDK로 업데이트하고 기존 소스 (현재 보유한 프로젝트의 소스)로 새 프로젝트를 작성하기 만하면됩니다.
자동으로 proguard.cfg
채우기가 생성됩니다.
그래도 수동으로 작성하려면 다음을 포함해야합니다.
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontwarn android.support.**
-verbose
-dontoptimize
-dontpreverify
-keepattributes *Annotation*
-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 com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
위의 모든 질문에 답한 것 같습니다.
업데이트 :
한 줄씩 설명 :
#Use 5 step of optimization
#-optimizationpasses 5
#When not preverifing in a case-insensitive filing system, such as Windows. This tool will unpack your processed jars,(if using windows you should then use):
-dontusemixedcaseclassnames
#Specifies not to ignore non-public library classes. As of version 4.5, this is the default setting
-dontskipnonpubliclibraryclasses
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
-dontwarn android.support.**
#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.
-verbose
#The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. Note that the Dalvik VM also can't handle aggressive overloading (of static fields).
#To understand or change this check http://proguard.sourceforge.net/index.html#/manual/optimizations.html
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
#To repackage classes on a single package
#-repackageclasses ''
#Uncomment if using annotations to keep them.
#-keepattributes *Annotation*
#Keep classes that are referenced on the AndroidManifest
-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.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
#Compatibility library
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
#To maintain custom components names that are used on layouts XML.
#Uncomment if having any problem with the approach below
#-keep public class custom.components.package.and.name.**
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
#To remove debug logs:
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** w(...);
}
#To avoid changing names of methods invoked on layout's onClick.
# Uncomment and add specific method names if using onClick on layouts
#-keepclassmembers class * {
# public void onClickButton(android.view.View);
#}
#Maintain java native methods
-keepclasseswithmembernames class * {
native <methods>;
}
#To maintain custom components names that are used on layouts XML:
-keep public class * extends android.view.View {
public <init>(android.content.Context);
}
-keep public class * extends android.view.View {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keep public class * extends android.view.View {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
#Maintain enums
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#To keep parcelable classes (to serialize - deserialize objects to sent through Intents)
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
#Keep the R
-keepclassmembers class **.R$* {
public static <fields>;
}
###### ADDITIONAL OPTIONS NOT USED NORMALLY
#To keep callback calls. Uncomment if using any
#http://proguard.sourceforge.net/index.html#/manual/examples.html#callback
#-keep class mypackage.MyCallbackClass {
# void myCallbackMethod(java.lang.String);
#}
#Uncomment if using Serializable
#-keepclassmembers class * implements java.io.Serializable {
# private static final java.io.ObjectStreamField[] serialPersistentFields;
# private void writeObject(java.io.ObjectOutputStream);
# private void readObject(java.io.ObjectInputStream);
# java.lang.Object writeReplace();
# java.lang.Object readResolve();
#}
업데이트 2 :
가장 최근의 ADT / Proguard -keepclasseswithmembers
대신-keepclasseswithmembernames
As of ADT 16 at least, you can indeed add the line in project.properties
, and it will be preserved. You can try changing the target SDK version, and see that project.properties
is updated accordingly but the added line is still there. So, I think the warning is just badly worded; it means to say that settings in the file such as target
will be overwritten with project settings, rather than vice versa.
Changes to ProGuard configuration came about with ADT version 17. ProGuard was updated from 4.4 to 4.7 and the difference in the configuration file reference already note was introduced. Note that existing projects would remain unchanged, leaving them without the newer rule set included in this and newer ADT versions. Relevant doc for newer configuration arrangement, already noted by ligi above, are available at:-
http://tools.android.com/recent/proguardimprovements "Second, we've changed the way configuration files are handled."
You can add the line to build.properties
, as mentioned in default.properties
.
참고URL : https://stackoverflow.com/questions/4732656/enabling-proguard-in-eclipse-for-android
'IT박스' 카테고리의 다른 글
새로운 구문 중 하나 대신 일반 오래된 Thread 객체를 사용하는 것이 더 좋은 경우가 있습니까? (0) | 2020.07.27 |
---|---|
PHP에서 cURL을 사용한 RAW POST (0) | 2020.07.27 |
매개 변수를 통한 캐시 버스 팅 (0) | 2020.07.27 |
명령 행 출력 억제 (0) | 2020.07.27 |
leiningen-지역 항아리에 의존성을 추가하는 방법? (0) | 2020.07.27 |