gpt4 book ai didi

google-play-services - 为什么我在使用 Proguard 时从 Play Services lib 得到 ClassNotFoundException?

转载 作者:行者123 更新时间:2023-12-01 09:50:02 25 4
gpt4 key购买 nike

我刚刚在我的构建中打开了 ProGuard,现在我得到了一个

java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.chimera.GmsModuleInitializer" on path: DexPathList[[zip file "/system/app/PlayGames.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

文档说,Android Gradle 插件应该包含我使用 Proguard 和 Play 服务所需的一切:

Note: ProGuard directives are included in the Play services client libraries to preserve the required classes. The Android Plugin for Gradle automatically appends ProGuard configuration files in an AAR (Android ARchive) package and appends that package to your ProGuard configuration. During project creation, Android Studio automatically creates the ProGuard configuration files and build.gradle properties for ProGuard use. To use ProGuard with Android Studio, you must enable the ProGuard setting in your build.gradle buildTypes. For more information, see the ProGuard guide.

这是我的应用模块 build.gradle 文件的重要部分:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
...
}
...
buildTypes {
...{
applicationIdSuffix ".debug"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}


dependencies {
...

//google play services
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
}

这是我的顶级 build.gradle 文件:

buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}

allprojects {
repositories {
jcenter()
mavenCentral()
}
}

我错过了什么?

最佳答案

ClassNotFoundException通常发生在应用程序试图通过其字符串名称加载类但找不到具有指定名称的类的定义时。

从这里forum ,您可以通过添加 com.google.android.gms.** { *; 来修复它

Just add to your proguard-project.txt:

  • keep class com.google.android.gms.** { *; }
  • dontwarn com.google.android.gms.**

您还可以查看此 SO question 中的建议评论.

Google Play Services aars contain proguard.txt with the necessary clauses. So the setting shouldn't really be necessary. You can investigate what happened with the fragment in ProGuard output files. Check app/build/output/mapping/{buildVariant}/usage.txt and mapping.txt. The fragment should be mentioned in one of those.

希望这对您有所帮助!

关于google-play-services - 为什么我在使用 Proguard 时从 Play Services lib 得到 ClassNotFoundException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39279008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com