在Android Studio中出现奇怪的错误,网上没有类似的情况,也不知道原因。

huangapple go评论58阅读模式
英文:

Strange error in android studio, nothing similar online and no idea of the cause

问题

I am a new android developer, and every time I try to run the emulator to test my app I get the following error:

2020-08-05 15:08:30.625 8361-8361/com.example.tender E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tender, PID: 8361
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzx;
    at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source:0)
    at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source:4)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2388)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2358)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7239)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697)
    at android.app.ActivityThread.access$1300(ActivityThread.java:237)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzx" on path: DexPathList[[zip file "/data/app/~~7yQ-4JW3qh-QJVNZiOJdsA==/com.example.tender-hor871ahRQoy1oE54-r8dg==/base.apk"],nativeLibraryDirectories=[/data/app/~~7yQ-4JW3qh-QJVNZiOJdsA==/com.example.tender-hor871ahRQoy1oE54-r8dg==/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source:0)
    at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source:4)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2388)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2358)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7239)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697)
    at android.app.ActivityThread.access$1300(ActivityThread.java:237)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Any idea what could be causing this? I reverted my changes for the last two days to no avail, and searched google with nobody experiencing anything similar. If someone can make sense of the error, please help. For context, I recently added the Google Places SDK into my app, but this error occurs even when I comment out all the code related to that.

EDIT: As requested, here is my module-level build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.example.tender"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services:8.4.0'
    implementation 'com.google.android.libraries.places:places:2.2.0'
}

Please note that this translation doesn't include the code part.

英文:

I am a new android developer, and every time I try to run the emulator to test my app I get the following error:

2020-08-05 15:08:30.625 8361-8361/com.example.tender E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tender, PID: 8361
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzx;
    at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source:0)
    at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source:4)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2388)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2358)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7239)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697)
    at android.app.ActivityThread.access$1300(ActivityThread.java:237)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzx" on path: DexPathList[[zip file "/data/app/~~7yQ-4JW3qh-QJVNZiOJdsA==/com.example.tender-hor871ahRQoy1oE54-r8dg==/base.apk"],nativeLibraryDirectories=[/data/app/~~7yQ-4JW3qh-QJVNZiOJdsA==/com.example.tender-hor871ahRQoy1oE54-r8dg==/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source:0) 
    at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source:4) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2388) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2358) 
    at android.app.ActivityThread.installProvider(ActivityThread.java:7239) 
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697) 
    at android.app.ActivityThread.access$1300(ActivityThread.java:237) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:223) 
    at android.app.ActivityThread.main(ActivityThread.java:7656) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

Any idea what could be causing this? I reverted my changes for the last two days to no avail, and searched google with nobody experiencing anything similar. If someone can make sense of the error, please help. For context, I recently added the Google Places SDK into my app, but this error occurs even when I comment out all the code related to that.

EDIT: As requested, here is my module-level build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.example.tender"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services:8.4.0'
    implementation 'com.google.android.libraries.places:places:2.2.0'

}

答案1

得分: 2

无法评论,但我假设您在构建时正在使用R8或Proguard,并且它正在通过反射查找在Google Places SDK中混淆类/字段/接口等。

查找该库的相关规则,将其包含在您的R8/Proguard规则文件中,以便在构建时保持不混淆。

编辑:另外,您是否在此应用程序中使用multidex?

编辑2:与评论中的OP一起工作 - 问题似乎源于将旧的通用捆绑的“play-services”库与特定的play-services库(如地图和位置)一起使用。删除捆绑库解决了他们的问题。

英文:

I can't comment yet, but I'm assuming you're using R8 or Proguard when building, and it's obfuscating classes/fields/interfaces etc within the Google Places SDK that it tries to find at runtime through reflection.

Find the relevant rules for that library to include within your R8/Proguard rules file so they'll remain un-obfuscated when building.

EDIT: Also, are you using multidex with this application?

EDIT2: Worked with OP in the comments - issue seems to have stemmed from using the older general purpose bundled 'play-services' library in conjunction with the specific play-services libraries (like maps and places). Removing the bundled library fixed their issue.

huangapple
  • 本文由 发表于 2020年8月6日 04:14:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/63272881.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定