Android支持v4 22.2.0的Proguard配置

时间:2015-06-04 13:25:30

标签: java android maven gradle proguard

在更新Gradle Android版本的依赖关系以使用来自本地Maven extras存储库(在SDK中)的com.android.support:support-v4:22.2.0之后,Proguard开始抛出这些问题。

Warning: android.support.v4.app.DialogFragment: can't find referenced class android.support.v4.app.DialogFragment$DialogStyle
Warning: android.support.v4.app.FragmentTransaction: can't find referenced class android.support.v4.app.FragmentTransaction$Transit
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$ResolvedLayoutDirectionMode
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$LayoutDirectionMode
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$LayerType
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$AccessibilityLiveRegion
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$ImportantForAccessibility
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$OverScroll
Warning: android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$EdgeGravity
Warning: android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$LockMode
Warning: android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$State
Warning: there were 11 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)

只需添加-dontwarn android.support.v4.**解决问题,但我想要一个更具体/更优雅的解决方案,而不是忽略support.v4包上的所有问题

任何人都可以说出应该添加哪些规则,所以这些类/ @接口是否由Proguard正确处理?

2 个答案:

答案 0 :(得分:15)

唯一的解决方案就是你所提到的,即-dontwarn android.support.v4.**。这实际上取自<path-to-android-sdk>/tools/proguard/proguard-android.txt,其中包含:

# 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.**

答案 1 :(得分:3)

根据Android团队设置不警告支持库类是安全的。您可以通过以下方式执行此操作:

## Support library
-dontwarn android.support.**