【问题标题】:Proguard error after adding Glide v4添加 Glide v4 后的 Proguard 错误
【发布时间】:2017-09-15 06:17:43
【问题描述】:

添加 glide v4 库后,我无法生成启用 proguard 的 apk。 我在 proguard-rules 中添加了以下几行

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

在构建时显示以下错误。

警告:com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool: 找不到引用的字段“android.graphics.Bitmap$Config HARDWARE” 在库类 android.graphics.Bitmap$Config

【问题讨论】:

    标签: android proguard android-glide


    【解决方案1】:

    使用以下命令可以忽略这些警告:

    -dontwarn com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool
    -dontwarn com.bumptech.glide.load.resource.bitmap.Downsampler
    -dontwarn com.bumptech.glide.load.resource.bitmap.HardwareConfigState
    

    看到这个post

    【讨论】:

      【解决方案2】:

      Proguard

      如果您使用 proguard,您可能需要在您的 proguard.cfg 中添加以下行:

      -keep public class * implements com.bumptech.glide.module.GlideModule
      -keep public class * extends com.bumptech.glide.module.AppGlideModule
      -keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
        **[] $VALUES;
        public *;
      }
      

      如果您是targeting any API level less than Android API 27,还包括:

      -dontwarn com.bumptech.glide.load.resource.bitmap.VideoDecoder
      

      VideoDecoder 使用 API 27 API,这可能会导致 proguard 警告,即使在旧版 Android 设备上不会调用较新的 API。

      【讨论】:

        【解决方案3】:

        我假设您从 this glide page 获取您的 proguard 规则,但它写错了。替换下一行

        -keep public class * extends com.bumptech.glide.AppGlideModule

        用这个:

        -keep public class * extends com.bumptech.glide.module.AppGlideModule

        如您所见,module 包丢失。它也被正确记录on README page。您还可以从 External Libraries 检查您的 AppGlideModule 类路径。

        【讨论】:

          【解决方案4】:

          您也可以将您的compileSdkVersion 增加到 26。这会照顾 Glide v4 使用的新功能。

          【讨论】:

            猜你喜欢
            • 2017-12-24
            • 2018-09-08
            • 2016-01-21
            • 1970-01-01
            • 2023-03-19
            • 1970-01-01
            • 1970-01-01
            • 2023-04-03
            • 1970-01-01
            相关资源
            最近更新 更多