Android Support v4 22.2.0 的 Proguard 配置
Posted
技术标签:
【中文标题】Android Support v4 22.2.0 的 Proguard 配置【英文标题】:Proguard configuration for Android Support v4 22.2.0 【发布时间】:2015-08-19 03:16:08 【问题描述】:在更新 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 正确处理这些类/@interfaces?
【问题讨论】:
我也有同样的问题。 即使我多次遇到这个问题,但我唯一能解决的办法是使用-dontwarn
【参考方案1】:
唯一的解决方案是你提到的,即-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.**
【讨论】:
【参考方案2】:根据 Android 团队,为支持库类设置不警告是安全的。您可以通过以下方式执行此操作:
## Support library
-dontwarn android.support.**
【讨论】:
什么问题?你的应用崩溃了吗? 不,但构建是,这让我担心 不就是因为警告吗? @MarekSebera 答案由 Google 自己在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.
@Sufian 把你的评论变成答案,我会接受它作为正确答案,这个答案与proguard-android.txt
的内容并不完全相同,所以这是你的机会以上是关于Android Support v4 22.2.0 的 Proguard 配置的主要内容,如果未能解决你的问题,请参考以下文章
android.support.v4与Android.support.v7
尝试在空对象引用上调用虚拟方法“void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapt
抽屉布局在 Xamarin.Android.Support.Core.UI 和 Xamarin.Android.Support.V4 中都存在