【问题标题】:Why do I need these proguard rules for Google Play Services为什么我需要 Google Play 服务的这些保护规则
【发布时间】:2017-12-11 18:56:26
【问题描述】:

我刚刚升级到最新的 google play 服务 (11.6.0)。当我使用 proguard 构建时,我现在收到以下警告:

Warning: com.google.android.gms.gcm.zza: can't find referenced method 'android.app.NotificationChannel getNotificationChannel(java.lang.String)' in library class android.app.NotificationManager
Warning: com.google.android.gms.gcm.zza: can't find referenced class android.app.NotificationChannel
Warning: com.google.android.gms.gcm.zza: can't find referenced class android.app.NotificationChannel
Warning: com.google.android.gms.gcm.zza: can't find referenced method 'void createNotificationChannel(android.app.NotificationChannel)' in library class android.app.NotificationManager
Warning: com.google.android.gms.gcm.zza: can't find referenced method 'android.app.Notification$Builder setChannelId(java.lang.String)' in library class android.app.Notification$Builder
Warning: com.google.android.gms.internal.zzbga: can't find referenced method 'boolean isInstantApp()' in library class android.content.pm.PackageManager
Warning: com.google.android.gms.internal.zzbgb: can't find referenced method 'boolean isInstantApp(java.lang.String)' in library class android.content.pm.PackageManager

为什么我会看到这个?我认为 GMS 处理了它自己的 Proguard 规则。来自文档link:

注意:ProGuard 指令包含在 Play 服务客户端中 库以保留所需的类。 Android 插件 Gradle 自动在 AAR 中附加 ProGuard 配置文件 (Android ARchive) 打包并将该包附加到您的 ProGuard 配置。在项目创建过程中,Android Studio 会自动 创建 ProGuard 配置文件和 build.gradle 属性 供 ProGuard 使用。要将 ProGuard 与 Android Studio 一起使用,您必须启用 build.gradle buildTypes 中的 ProGuard 设置。更多 信息,请参阅 ProGuard 指南。

【问题讨论】:

    标签: android google-play-services


    【解决方案1】:

    根据release notes for Google Play services 11.2.0:

    当您将应用的 Play 服务依赖项升级到 11.2.0 或更高版本时,还必须更新应用的 build.gradle 以指定 compileSdkVersion 至少为 26 (Android O)。这不会改变您应用的运行方式。

    更新您的compileSdkVersion(请注意,您不需要同时更新您的targetSdkVersion - 可以稍后完成)以便可以找到在 API 26 中添加的引用方法。

    【讨论】:

    • 完美,这是正确答案。如果您无法更新目标 SDK 版本(您应该始终以最新版本为目标,但如果出于某种原因绝对必须这样做),那么 11.0.4 是 API 25 可以针对的最高版本,因此您可以使用它.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    相关资源
    最近更新 更多