Android용 Eclipse에서 ProGuard 사용
ProGuard for Android의 새 문서에는 프로젝트 홈 디렉토리의 default.properties 파일에 줄을 추가하라는 내용이 나와 있습니다.하지만 이 파일을 열었을 때 맨 위에 다음과 같이 읽었습니다.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
내가 뭘 빼놓았나요?
또한 Eclipse의 프로덕션 빌드에 대해서만 ProGuard를 활성화하는 방법이 있습니까(즉, 완제품을 내보낼 때)?
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'
...
}
}
여기서 내가 계속 업데이트하는 프로가드 "기본" 파일을 확인할 수 있습니다. 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.properties2.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
동일한 것을 검색하고 있었기 때문에 후속 조치일 뿐입니다. 그리고 여기에 있는 답변은 구식입니다. 최근에는 기본 프로가드 구성이 sdkdir에 있습니다. 따라서 이것만 project.properties에 넣으면 됩니다.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
프로젝트별로 수정하려면 proguard-proguard 프로젝트를 생성합니다.txt 및 행을 다음으로 변경합니다.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
적어도 ADT 16부터는 실제로 라인을 추가할 수 있습니다.project.properties그리고 그것은 보존될 것입니다.대상 SDK 버전을 변경해 볼 수 있습니다.project.properties이에 따라 업데이트되지만 추가된 행은 계속 남아 있습니다.그래서, 저는 그 경고가 단지 나쁜 단어라고 생각합니다; 그것은 파일의 설정을 의미합니다.target프로젝트 설정으로 덮어쓰는 대신 프로젝트 설정으로 덮어씁니다.
ADT 버전 17에서는 ProGuard 구성이 변경되었습니다.ProGuard가 4.4에서 4.7로 업데이트되었으며 구성 파일 참조의 차이가 이미 소개되었습니다.기존 프로젝트는 변경되지 않은 상태로 유지되므로 이 ADT 버전과 최신 ADT 버전에 포함된 최신 규칙 집합이 없습니다.위의 ligi에서 이미 언급한 새로운 구성 배치 관련 문서는 다음 사이트에서 확인할 수 있습니다.
http://tools.android.com/recent/proguardimprovements "두 번째로, 구성 파일을 처리하는 방식을 변경했습니다."
다음에 줄을 추가할 수 있습니다.build.properties에서 언급한 바와 같이default.properties.
언급URL : https://stackoverflow.com/questions/4732656/enabling-proguard-in-eclipse-for-android
'programing' 카테고리의 다른 글
| 원격 서버의 Mongodump (0) | 2023.05.29 |
|---|---|
| Rect를 그리거나 그렇지 않으면 Rect를 그리거나 하지 않습니다(drawRect/Core Graphics 대 subview/images 중 언제 사용해야 하며 그 이유는 무엇입니까?) (0) | 2023.05.29 |
| Nodejs의 Mongodb vs Postgres (0) | 2023.05.29 |
| 선택한 쿼리의 출력을 하나의 어레이에 포스트그레스로 저장 (0) | 2023.05.29 |
| PostgreSQL에서 세션 ID에 적합한 임의 문자열을 어떻게 생성합니까? (0) | 2023.05.29 |