关于ProGuard for Android的新文档说,要在项目主目录的default.properties文件中添加一行.但是,在打开此文件时,我在顶部阅读:
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
另外,有没有办法让ProGuard仅用于Eclipse的生产构建(即,在导出成品时)?
我想在一个使用android库项目的android应用程序中使用proguard ,我收到以下错误:
java.io.IOException: Can't write
[/private/var/folders/Pg/PgUpPJQ-E5qxL7jX6kpdCE+++TI/-Tmp-/android_3140050575281008652.jar]
(Can't read [proguard.ClassPathEntry@1f8d244]
(Duplicate zip entry
[be.class == android_144638064543155619.jar:com/comp/dp/library/R$anim.class]))
at proguard.OutputWriter.writeOutput(OutputWriter.java:224)
at proguard.OutputWriter.execute(OutputWriter.java:120)
at proguard.ProGuard.writeOutput(ProGuard.java:391)
at proguard.ProGuard.execute(ProGuard.java:152)
at proguard.ProGuard.main(ProGuard.java:499)
Run Code Online (Sandbox Code Playgroud)
我的proguard.cfg文件就是这个,还有一些-libraryjars引用了rt.jar几个其他依赖库.
我的猜测是这个问题与使用Library Project有关,而proguard正在尝试两次处理来自库项目的条目.但我不确定应该用哪种方法来解决这个问题.
任何建议/方向都非常感谢.
更新1: 通过删除-injars bin/classes我能够解决这个问题.我的猜测是因为proguard处理库项目和应用程序项目.class库项目的文件被处理了两次.一旦进入库项目的bin/classes文件夹,另一次进入应用程序项目的bin/classes文件夹.
我正在使用最新的Android SDK(4.1),我尝试导出已启用Proguard的签名jar.但是,在反编译优化的APK之后,我注意到我希望内联的方法不是.
我知道Proguard运行是因为代码被正确混淆了.所以为了确认这一点,我在我的Activity中添加了这个方法:
private void testInlining()
{
mConfig = null;
}
Run Code Online (Sandbox Code Playgroud)
这个私有方法在我的活动中只被调用一次,并且因为它是私有的,所以优化器应该非常明显它只被调用一次并且它应该被内联.
文档说明默认情况下启用所有优化,并且Proguard"内联方法很短或只调用一次".
是否有一个特定的标志我应该给Proguard启用内联?
编辑
我的proguard配置文件包含
-optimizationpasses 5
-allowaccessmodification
-overloadaggressively
-repackageclasses ''
-dontskipnonpubliclibraryclasses
Run Code Online (Sandbox Code Playgroud)
编辑
使用后
-whyareyoukeeping class com.templatecompany.templateappname.EntryPointActivity {*;}
Run Code Online (Sandbox Code Playgroud)
我得到了没有内联方法的原因:
[proguard] com.templatecompany.templateappname.EntryPointActivity: void testInlining() (20:21)
[proguard] is invoked by com.templatecompany.templateappname.EntryPointActivity: com.td.media.ivConnection.IvConfig getIvConfig() (14:15)
[proguard] implements com.td.widget.MainActivity: com.td.media.ivConnection.IvConfig getIvConfig()
[proguard] is invoked by com.td.widget.MainActivity: void onCreate(android.os.Bundle) (140:175)
[proguard] implements android.app.Activity: void onCreate(android.os.Bundle)
[proguard] is a library method.
Run Code Online (Sandbox Code Playgroud)
但我不确定testInlining这个方法getIvConfig在另一个方法反过来使用的方法中使用的事实是如何阻止内联testInlining的getIvConfig.
我正在尝试将ProGuard与我的一个应用程序一起使用,让我们说A.这个应用程序包含另一个应用程序作为库(比方说B).这是我的proguard文件.
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-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
-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 …Run Code Online (Sandbox Code Playgroud) 我明白了,但找不到在哪里添加?我还应该使用花括号{}之类的吗?
# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
Run Code Online (Sandbox Code Playgroud)
代码:
dependencies {
/*TODO:-> Android default libraries*/
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
/*TODO:-> For shows Database on Google Chrome*/
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.8@aar') {
transitive = true
}
/*TODO:-> For View binding*/
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
/*TODO:-> Server side libraries*/
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation …Run Code Online (Sandbox Code Playgroud)