Exoplayer2 在许多 Vivo 设备上抛出错误 class com.google.android.exoplayer2.ui.PlayerView

Exoplayer2 throwing error inflating class com.google.android.exoplayer2.ui.PlayerView on many Vivo devices

我的 exoplayer2 在三星、摩托罗拉、小米、索尼等设备上的发布和调试版本都运行良好。

但是当我在 Play 商店发布我的应用程序时,它在 nexus 4(Android 版本 6.0.1)和一些 Vivo 型号(如 Vivo Y53、Y71 和 V5)等设备上抛出错误android 版本 6.0.1、7 和 8。

Crashlytics 显示此错误:由 android.view.InflateException 引起:二进制 XML 文件行 #153:膨胀 class com.google.android.exoplayer2.ui.PlayerView[=14 时出错=]

我的代码已包含 Error inflating class com.google.android.exoplayer2.ui.SimpleExoPlayerView 中提到的属性,但在少数设备中仍面临问题。

会不会是因为 Vivo 和 Nexus 设备中的自定义 ROM?

找到解决方案,这不是任何开发错误,因为如果它是任何代码错误,那么它应该在多个设备上发生。

所以,我最后的办法是纠正到底发生了什么。由于应用程序的 apk 是作为捆绑包上传的,如果用户在通过 ShareIt 或 Whatsapp 共享捆绑包 apk(侧载)后安装应用程序,它会崩溃,因为它是我们无法共享的应用程序捆绑包 属性从 bundle 生成的 APK。

因此,要检查用户是否通过侧载安装应用程序,我们可以添加 google 的播放核心库,让他们知道 "app is missing components. Please install from playstore".

Gradle:

implementation 'com.google.android.play:core:1.6.3'

onCreate() 中的应用程序 Class:

if (MissingSplitsManagerFactory.create(this)
         .disableAppIfMissingRequiredSplits()) {
      return;
      // Skip app initialization.
}

根据文档,请在 build.gradle(Module:app)

中添加以下行
compileOptions {
    targetCompatibility JavaVersion.VERSION_1_8
}

希望对您有所帮助。