Android 9 Pie 崩溃(com.google.android.gms...ClassNotFoundException)

Android 9 Pie crash (com.google.android.gms... ClassNotFoundException)

我在 Android 上发布了一款 Unity3D 游戏,到目前为止运行良好。 但是,Android Vitals Dashboard 现在报告了很多崩溃。详细信息如下:

By Android version: Android 9   4500    100.0%

堆栈跟踪:

java.lang.Error: FATAL EXCEPTION [Thread-360]
Unity version     : 2017.3.1p3
Device model      : Google Pixel
Device fingerprint: google/sailfish/sailfish:9/PQ2A.190305.002/5240760:user/release-keys
Caused by
  at lt.b (com.google.android.gms.policy_ads_fdr_dynamite@30000@30000.238272502.238272502:2)
  at ls.a (com.google.android.gms.policy_ads_fdr_dynamite@30000@30000.238272502.238272502:1)
  at lu.a (com.google.android.gms.policy_ads_fdr_dynamite@30000@30000.238272502.238272502:18)
  at com.google.android.gms.ads.internal.util.ar.a (com.google.android.gms.policy_ads_fdr_dynamite@30000@30000.238272502.238272502:10)
  at kx.a (com.google.android.gms.policy_ads_fdr_dynamite@30000@30000.238272502.238272502:7)
  at kx.run (com.google.android.gms.policy_ads_fdr_dynamite@30000@30000.238272502.238272502:2)
Caused by: java.lang.ClassNotFoundException: 
  at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:134)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:379)
  at ac.loadClass (com.google.android.gms.dynamite_dynamiteloader@16089081@16.0.89 (100400-239467275):4)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:312)

我的 AndroidResolverDependencies.xml 文件:

<dependencies>
  <packages>
    <package>com.android.support:customtabs:[26.0.0, 27.2.0[</package>
    <package>com.android.support:support-v4:[26.0.0, 27.2.0[</package>
    <package>com.google.android.gms:play-services-ads:17.2.0</package>
    <package>com.google.android.gms:play-services-analytics:11.8.0</package>
    <package>com.google.android.gms:play-services-base:[10.2.1, 12.1.0[</package>
    <package>com.google.android.gms:play-services-location:[10.2.1, 12.1.0[</package>
    <package>com.google.firebase:firebase-messaging:[10.2.1, 12.1.0[</package>
  </packages>
  <files>
    <file>Assets/Plugins/Android/android.arch.core.common-1.1.0.jar</file>
    <file>Assets/Plugins/Android/android.arch.core.runtime-1.1.0.aar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.common-1.1.0.jar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.livedata-core-1.1.0.aar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.runtime-1.1.0.aar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.viewmodel-1.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.customtabs-27.1.1.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-annotations-27.1.1.jar</file>
    <file>Assets/Plugins/Android/com.android.support.support-compat-27.1.1.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-core-ui-27.1.1.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-core-utils-27.1.1.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-fragment-27.1.1.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-media-compat-27.1.1.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-v4-27.1.1.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-ads-17.2.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-ads-base-17.2.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-ads-identifier-16.0.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-ads-lite-17.2.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-analytics-16.0.8.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-analytics-impl-16.0.8.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-base-16.1.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-basement-16.2.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-gass-17.2.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-location-16.0.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-measurement-base-16.3.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-measurement-sdk-api-16.3.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-places-placereport-16.0.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-stats-16.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-tagmanager-v4-impl-16.0.8.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-tasks-16.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.auto.value.auto-value-annotations-1.6.jar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-common-16.1.0.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-iid-17.1.2.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-iid-interop-16.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-measurement-connector-17.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-messaging-17.6.0.aar</file>
  </files>
</dependencies>
Target API level: 28
Minimum API level: 16

我在 Google AdMob's discussion group 中看到了一个类似的帖子,建议将以下内容添加到 AndroidManifest.xml 文件中:

<uses-library android:name="org.apache.http.legacy" android:required="false" />

但是:

  1. 我不确定问题是由任何与 Apache 相关的问题引起的 API。
  2. 恐怕这会限制我的应用程序的安装数量,因为由于 uses-library 声明,它在 Google Play 中可供较小的受众使用。

根据Behavior changes: apps targeting API level 28+

Apache HTTP client deprecation

With Android 6.0, we removed support for the Apache HTTP client. Beginning with Android 9, that library is removed from the bootclasspath and is not available to apps by default. To continue using the Apache HTTP client, apps that target Android 9 and above can add the following to their AndroidManifest.xml:

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

Note: The android:required="false" attribute is required for apps that have a minimum SDK of 23 or lower, because on devices with API levels lower than 24, the org.apache.http.legacy library is not available. (On those devices, the Apache HTTP classes are available on the bootclasspath.)

As an alternative to using the runtime Apache library, apps can bundle their own version of the org.apache.http library in their APK. If you do this, you must repackage the library (with a utility like Jar Jar) to avoid class compatibility issues with the classes provided in the runtime.