I wonder is it possible not to add the rule one by one for the
libraries, as some library seems does not mention about how to setup
proguard for them?
是的可能,不是为您在项目中使用的每个库逐个添加规则.尝试在proguard-rules.pro文件中添加以下内容.
-keep class !com.example.myproject.** { *; }
这个想法只是用你在proguard-rules.pro中使用的正则表达式来设置一个否定符.
但是,如果你没有混淆你的代码,那么使用proguard有什么意义呢.您可能希望在混淆后保持项目中的某些类不变.你只需要像其他库一样保留它们.例如 –
// I want to keep the classes in the `Models` package to remain unchanged
-keep class com.example.myproject.Models.** { *; }
-keepclassmembers class com.example.myproject.Model.** { *; }
无论如何,逐个添加规则并不是很难,因为你在混淆时会有更多的控制权.这是我的proguard-rules.pro.你可以看看它.
-useuniqueclassmembernames
-allowaccessmodification
-keep class com.google.** { *; }
-keep class com.journeyapps.** { *; }
-keep class com.makeramen.** { *; }
-keep class com.github.** { *; }
-keep class org.apache.** { *; }
-keep class com.flipboard.** { *; }
-keep class com.android.** { *; }
-keep class com.mikepenz.** { *; }
-keep class junit.** { *; }
-keep class org.mockito.** { *; }
-keep class android.support.v7.widget.SearchView { *; }
-keep class com.example.myproject.Models.** { *; }
-keepclassmembers class com.example.myproject.Model.** { *; }
-keepattributes Signature
-keepattributes *Annotation*
-dontwarn com.google.**
-dontwarn org.apache.**
-dontwarn android.support.**
-dontwarn org.junit.**
-dontwarn org.mockito.**
-dontwarn com.makeramen.**
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** w(...);
public static *** i(...);
public static *** e(...);
}