跳到内容

解决 Google Play Services 冲突

不同框架的不同插件可能会使用不同版本的 google-play-services 库,这可能导致您的项目因库版本过时而无法编译或崩溃。

以下部分为不同插件提供了解决方案。

您可以在 <Android SDK>/extras/google 路径下找到 Google Play Services 库。

该库有两种格式可用:

  1. 单体 jar 文件(在单个文件中包含所有 Google Play Services 组件):

    sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar
  2. 模块化 aar 文件(Android Archive),其中每个组件都在一个单独的文件中:

    sdk/extras/google/m2repository/com/google/android/gms/…

一个 aar 文件可以通过解压(aar 是一个 zip 压缩包)并提取其中的 classes.jar(库的代码)来精简为一个 jar 文件(目前并非所有框架都支持 aar)。

1. Cordova

Anchor link to

在 Cordova 上,所有 google play services 冲突都通过 gradle 自动解决。有时(例如,不同插件使用不同主版本的库),解决过程可能会失败,导致最终构建中出现同一库的两个不同版本。

2. Unity、Appcelerator Titanium

Anchor link to

您可以在插件(或示例项目)中找到 Google Play Services 库。它们易于更新、更改或移除以解决可能的冲突:

Terminal window
rm -rf Assets/Plugins/Android/google-play-services_lib/libs
rm -rf Assets/Plugins/Android/google-play-services_lib/res
cp ${ANDROID_HOME}/extras/google/m2repository/com/google/android/gms/play-services-analytics/8.4.0/play-services-analytics-8.4.0.aar Assets/Plugins/Android/
cp ${ANDROID_HOME}/extras/google/m2repository/com/google/android/gms/play-services-ads/8.4.0/play-services-ads-8.4.0.aar Assets/Plugins/Android/

3. Adobe Air

Anchor link to

获取 ANE 扩展,将其解压、修改,然后重新打包。

使用以下 PushNotification.ane 的示例:

Terminal window
unzip PushNotification.ane -d tmp

此命令会将 .ane 文件的内容提取到 tmp 目录中。

现在,在 tmp/META-INF/ANE/Android-ARM/tmp/META-INF/ANE/Android-x86/ 目录中,您可以找到所有可能已被修改、更新或移除的库:android-support_、play-services_ 等。

如果您仍然遵循上述文档中的链接,请更改 tmp/META-INF/ANE/Android-ARM/platform.xmltmp/META-INF/ANE/Android-x86/platform.xml,然后将扩展重新压缩,一切应该就能正常工作。

如果您遇到以下错误:

PushNotification.ane is not a valid native extension file.

请按照以下步骤重新打包扩展:

  1. 删除 tmp/META-INF/ANE/Android-ARM/platform.xmltmp/META-INF/ANE/Android-x86/platform.xml
  2. 根据上述链接中的指南,改为修改 tmp/META-INF/ANE/Android-ARM/android-depends.xmltmp/META-INF/ANE/Android-x86/android-depends.xml
  3. 运行以下 bash 命令:
Terminal window
#rename platform.xml on iOS, required to repackage the extension
mv tmp/META-INF/ANE/iPhone-ARM/platform.xml tmp/META-INF/ANE/iPhone-ARM/platform-iOS.xml
#pack the extension back with adt
cd tmp/META-INF/ANE/
“${flex.sdk}/bin/adt" -package -target ane PushNotification.ane extension.xml -swc ../../../../SWC-Pushwoosh/PushNotification.swc -platform iPhone-ARM -platformoptions iPhone-ARM/platform-iOS.xml -C iPhone-ARM/ . -platform Android-ARM -platformoptions Android-ARM/android-depends.xml -C Android-ARM/ . -platform Android-x86 -C Android-x86/ . -platformoptions Android-x86/android-depends.xml -platform default -C default/ .

您可以在这里找到 PushNotification.swc:https://github.com/Pushwoosh/pushwoosh-adobe-air/blob/master/SWC-Pushwoosh/PushNotification.swc

4. Unreal Engine

Anchor link to

Unreal Engine 和 Pushwoosh Plugin 几乎总是会相互冲突。这是因为 Unreal Engine 默认包含 Google Play services,并且不同版本的引擎使用不同版本的这些库。Pushwoosh 插件也使用这些库,但使用的是不同的子集。在集成用于 Unreal Engine 的 Pushwoosh Plugin 时务必小心。即使您的项目看起来编译和运行良好,也要确保 Pushwoosh 和 Unreal Engine 使用相同版本的 Google Play Services。在同一个项目中使用不同版本的 google-play-services 会导致未定义的行为。

要解决冲突,您应执行以下操作:

1. 确定项目中已在使用哪些 Google Play services 库。检查 ${UNREAL_PROJECT}/Intermediate/Android/APK/JavaLibs${UNREAL_PROJECT}/Intermediate/Android/APK/libs 目录。例如,在使用 Unreal Engine 4.15 创建的示例项目中,有以下库:

JavaLibs:

  • downloader_library
  • play-services-ads-lite-9.2.0
  • play-services-auth-base-9.2.0
  • play-services-basement-9.2.0
  • play-services-drive-9.2.0
  • play-services-gass-9.2.0
  • play-services-plus-9.2.0
  • support-v4-23.0.0
  • play-services-ads-9.2.0
  • play-services-auth-9.2.0
  • play-services-base-9.2.0
  • play-services-clearcut-9.2.0
  • play-services-games-9.2.0
  • play-services-nearby-9.2.0
  • play-services-tasks-9.2.0
  • pushwoosh-ue-plugin // 由 Pushwoosh 插件添加

libs:

  • SystemUtils.jar
  • VrApi.jar
  • play-services-gcm-9.2.0.jar // 由 Pushwoosh 插件添加
  • play-services-iid-9.2.0.jar // 由 Pushwoosh 插件添加

2. 如果 Pushwoosh 和 Unreal Engine 中使用的 play-services* 库的版本不匹配,请从 Pushwoosh 插件中移除这些库。

3. 确定应向 Pushwoosh Plugin 添加哪些缺失的库。该插件需要 android-support-v4、play-services-base、play-services-basement、play-services-gcm 和 play-services-iid 库。对于示例项目,只有 play-services-gcmplay-services-iid 不重叠,因此在这种特定情况下,它们是唯一需要添加的库。

4. 通过将 Android SDK 中的 .jar 文件放置在 https://github.com/Pushwoosh/pushwoosh-unreal-engine/tree/master/Plugins/Pushwoosh/lib/Android/libs 中来添加库。Google Play 库的位置在本文开头有描述。

与我们分享您的反馈

Anchor link to

您的反馈有助于我们创造更好的体验。如果您在 SDK 集成过程中遇到任何困难,请通过此表单与我们分享您的想法。