[英]Configure proguard to exclude library jar which extends android.content.Context
我正在將一個庫集成到一個項目的設備中,該項目將嵌入到設備操作系統中。 為此,我們正在集成一個庫jar,它覆蓋了Android框架Context。
因此,嘗試為應用程序啟用Proguard會給我以下錯誤 - “根據程序類有220個庫類實例”。
所有這些文件都是小部件和視圖。 我怎樣才能解決這個問題?
這是我的proguard-project.txt的內容
-injars bin/classes
-outjars bin/classes-processed.jar
-libraryjars /Users/me/android-sdk-mac_86/platforms/android-15/android.jar
-libraryjars libs/library-that-overrides-context.jar
-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.content.Context
這是我的proguard-android.txt的內容
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# 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
# 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.
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# 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*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-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>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
Android Ant / Eclipse構建會自動為您指定所有必需的-injars / -outjars / -libraryjars選項。 如果您有自定義構建過程,則應僅指定這些選項。 否則,您將收到許多關於重復類和可能的其他問題的警告。
如果確實需要指定-injars / -outjars / -libraryjars選項,則使用-injars指定的類可以依賴於使用-libraryjars指定的類,而不是相反。 (CFR)。 ProGuard手冊>故障排除> 警告:庫類......取決於程序類......
即使我將我的庫標記為libraryjar,我也必須添加這些行
-keep public class android.content.** { *; }
-keep public class android.content.** { *; }
該項目的ProGuard配置文件來解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.