【问题标题】:proguard-rules.pro is not usedproguard-rules.pro 未使用
【发布时间】:2019-03-29 09:07:18
【问题描述】:

这是我的proguard-rules.pro 文件:(我不确定我是否真的需要包含com.github.chrisbanes 的规则)

-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
-keep class com.squareup.** { *; }
-dontwarn com.squareup.**
-keep class com.github.chrisbanes.** { *; }
-dontwarn com.github.chrisbanes.**

因为我用过:

api 'com.google.android.gms:play-services-ads:17.2.0'
api 'androidx.appcompat:appcompat:1.0.2'
api 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.chrisbanes:PhotoView:2.3.0'

我之前将那个proguard-rules.pro 文件(没有com.github.chrisbanes 库)用于其他具有谷歌广告和毕加索库的应用程序并且它工作正常。

现在我在尝试生成签名 APK 时遇到一堆错误,例如:

Note: the configuration keeps the entry point 'com.google.android.gms.internal.ads.zzapm { void requestInterstitialAd(android.content.Context,com.google.android.gms.ads.mediation.MediationInterstitialListener,android.os.Bundle,com.google.android.gms.ads.mediation.MediationAdRequest,android.os.Bundle); }', but not the descriptor class 'com.google.android.gms.ads.mediation.MediationInterstitialListener'
Note: the configuration keeps the entry point 'com.google.android.gms.internal.ads.zzapm { void requestInterstitialAd(android.content.Context,com.google.android.gms.ads.mediation.MediationInterstitialListener,android.os.Bundle,com.google.android.gms.ads.mediation.MediationAdRequest,android.os.Bundle); }', but not the descriptor class 'com.google.android.gms.ads.mediation.MediationAdRequest'
Note: the configuration keeps the entry point 'com.squareup.picasso.BitmapHunter { android.graphics.Bitmap decodeStream(okio.Source,com.squareup.picasso.Request); }', but not the descriptor class 'okio.Source'
Note: the configuration keeps the entry point 'com.squareup.picasso.Downloader { okhttp3.Response load(okhttp3.Request); }', but not the descriptor class 'okhttp3.Request'

Android Studio 似乎根本没有使用我的 proguard-rules.pro 文件。

此外,与之前的应用相比,此应用的新之处在于,在此应用中,我首次使用 androidx 并针对 API 28。

您知道问题出在哪里以及如何解决吗?

另外,我可以只使用-ignorewarnings 并生成签名的 APK 吗?我的应用还能正常运行吗?

【问题讨论】:

    标签: android proguard android-proguard


    【解决方案1】:

    检查您的 proguard-rules.pro 的位置。它应该在 app 模块目录中。

    前段时间我也遇到过同样的问题。我的 proguard-rules.pro 位于项目的根目录中,我将其移至 app 目录。

    【讨论】:

    • 刚刚检查过,它在应用模块目录中。
    【解决方案2】:

    我可以只使用 -ignorewarnings 并生成签名的 APK 吗?我的应用还能正常运行吗?

    通常,您不应在不知道其影响的情况下简单地忽略 proguard 警告,但有时可以忽略警告,因为您的应用可能未引用这些类,因此您可以尝试添加以下配置并检查您的应用是否可以正常工作。

    -keep class com.google.android.gms.**
    -dontwarn com.google.android.gms.**
    

    另外,您的错误日志实际上来自 proguard。尝试不同的 gms 版本,看看它是否有效。例如试试15.0.0

    api 'com.google.android.gms:play-services-ads:15.0.0'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 2021-03-09
      相关资源
      最近更新 更多