成功构建后由于谷歌播放服务导致离子抛出错误

Posted

技术标签:

【中文标题】成功构建后由于谷歌播放服务导致离子抛出错误【英文标题】:Ionic throwing error due to google play services after successful build 【发布时间】:2020-03-18 20:10:05 【问题描述】:

花了两天时间,我快疯了…… 我有一个一直运行良好的离子项目。我不小心将 ionic 更新到了 v5,这造成了严重破坏,我在解决问题的过程中结束了升级其他东西(android 库、cordova、npm 等)。虽然,我最终通过降级 ionic 版本来修复错误,但现在在构建过程中出现以下错误:

> Transform play-services-basement.aar (com.google.android.gms:play-services-basement:17.0.0) with AarTransform
> Transform play-services-measurement-base.aar (com.google.android.gms:play-services-measurement-base:17.1.0) with AarTransform
> Transform play-services-measurement-sdk-api.aar (com.google.android.gms:play-services-measurement-sdk-api:17.1.0) with AarTransform
> Transform play-services-ads-lite.aar (com.google.android.gms:play-services-ads-lite:18.3.0) with AarTransform
> Transform play-services-ads-identifier.aar (com.google.android.gms:play-services-ads-identifier:17.0.0) with AarTransform
> Transform play-services-tasks.aar (com.google.android.gms:play-services-tasks:17.0.0) with AarTransform
> Transform play-services-gass.aar (com.google.android.gms:play-services-gass:18.3.0) with AarTransform
> Transform legacy-support-v4.aar (androidx.legacy:legacy-support-v4:1.0.0) with AarTransform
> Transform play-services-ads.aar (com.google.android.gms:play-services-ads:18.3.0) with AarTransform
> Transform play-services-base.aar (com.google.android.gms:play-services-base:17.1.0) with AarTransform
> Transform play-services-audience.aar (com.google.android.gms:play-services-audience:17.0.0) with AarTransform
> Transform play-services-drive.aar (com.google.android.gms:play-services-drive:17.0.0) with AarTransform
> Transform play-services-plus.aar (com.google.android.gms:play-services-plus:17.0.0) with AarTransform
> Transform play-services-games.aar (com.google.android.gms:play-services-games:19.0.0) with AarTransform
> Task :app:generateReleaseResValues
> Task :app:generateReleaseResources
> Task :app:mergeReleaseResources
> Task :app:createReleaseCompatibleScreenManifests
> Task :app:processReleaseManifest
> Task :app:processReleaseResources

> Task :app:compileReleaseJavaWithJavac FAILED
25 actionable tasks: 25 executed
/home/myuser/Desktop/ionic/MyProject/platforms/android/app/src/main/java/com/berriart/cordova/plugins/GameHelper.java:43: error: package com.google.android.gms.games.request does not exist
import com.google.android.gms.games.request.GameRequest;
                                           ^
/home/myuser/Desktop/ionic/MyProject/platforms/android/app/src/main/java/com/berriart/cordova/plugins/GameHelper.java:174: error: cannot find symbol
    ArrayList<GameRequest> mRequests;
              ^
  symbol:   class GameRequest
  location: class GameHelper
/home/myuser/Desktop/ionic/MyProject/platforms/android/app/src/main/java/com/berriart/cordova/plugins/GameHelper.java:492: error: cannot find symbol
    public ArrayList<GameRequest> getRequests() 
                     ^
  symbol:   class GameRequest
  location: class GameHelper
/home/myuser/Desktop/ionic/MyProject/platforms/android/app/src/main/java/com/berriart/cordova/plugins/GameHelper.java:714: error: cannot find symbol
            mRequests = Games.Requests
                             ^
  symbol:   variable Requests
  location: class Games
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /home/myuser/Desktop/ionic/MyProject/platforms/android/app/src/main/java/nl/xservices/plugins/SocialSharing.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

下面是我的平台/android/project.properties

target=android-28
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=com.google.android.gms:play-services-base:+
cordova.system.library.2=com.google.android.gms:play-services-ads:+
cordova.system.library.3=androidx.annotation:annotation:1.0.0
cordova.system.library.4=com.google.android.gms:play-services-games:+
cordova.system.library.5=com.google.android.gms:play-services-plus:+
cordova.system.library.6=androidx.legacy:legacy-support-v4:1.0.0

我看到了几篇关于为 play-services-games 提供特定版本的帖子,因此我提供了基于此页面 https://developers.google.com/android/guides/setup 的版本。但是,它没有帮助。如果需要提供具体版本,应该提供什么?

令人讨厌的是,这段代码昨天运行得非常好,直到我搞砸了一些东西......

Ionic:

   ionic (Ionic CLI)             : 4.10.3 (/home/myuser/.npm-global/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.11.5
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.1.1

Cordova:

   cordova (Cordova CLI) : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms     : android 8.1.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 14 other plugins)

System:

   Android SDK Tools : 26.1.1 (/home/myuser/Android/Sdk)
   NodeJS            : v12.13.1 (/usr/bin/node)
   npm               : 6.12.1
   OS                : Linux 4.18

如果您能就此问题提供指点,我将不胜感激。

非常感谢,

道格

【问题讨论】:

GameRequest 类不再存在于播放服务中。它已于 2017 年弃用。因此,您也应该获得对原始设置版本的依赖...这是最新版本:com.google.android.gms:play-services-games:19.0.0 您好 emirc,非常感谢您的回答。你能帮我看看怎么做吗?我只是将版本号放在 com.google.android.gms:play-services-games:19.0.0 的 project.properties 中吗?还是我需要为所有内容输入版本号?还是我做点别的?当我查看日志时,看起来版本已经是 19.0.0(> 使用 AarTransform 转换 play-services-games.aar (com.google.android.gms:play-services-games:19.0.0))但是我需要硬编码吗? 【参考方案1】:

我遇到了同样的问题,正如 emirc 所说,这归结为 11 月 19 日发布的 com.google.android.gms:play-services-games 弃用了实时和回合制多人 API。见:https://developers.google.com/android/guides/releases

在我的情况下,依赖项是由 artberri/cordova-plugin-play-games-services 提取的,如果我参考您的错误日志,它对您来说似乎是一样的。在更新此插件之前,我们必须坚持使用 18.0.1 版本的依赖项,这很容易通过在添加时设置 ANDROID_PLAY_SERVICES_GAMES_VERSION 来完成:

cordova plugin add cordova-plugin-play-games-services --variable APP_ID=<...> --variable ANDROID_PLAY_SERVICES_GAMES_VERSION=18.0.1

【讨论】:

以上是关于成功构建后由于谷歌播放服务导致离子抛出错误的主要内容,如果未能解决你的问题,请参考以下文章

手动抛出错误离子2

离子 apk 签名错误

无法将离子与电容器集成,npm 抛出错误

离子服务抛出此错误代码请帮助

添加 Google Play 服务后无法构建 App

Spring Boot + Video 错误“由于网络错误导致视频播放中止”