简体   繁体   English

升级cordova-android 10后构建失败

[英]Build failing after upgrade cordova-android 10

When I upgraded cordova-android@9.0.0 to cordova-android@10.1.1 I've got a build problem when I run cordova build android --release --buildconfig=build.json当我将cordova-android@9.0.0升级到cordova-android@10.1.1时,我在运行cordova build android --release --buildconfig=build.json时遇到了构建问题

Problems:问题:

* What went wrong:
Some problems were found with the configuration of task ':app:processReleaseGoogleServices' (type 'GoogleServicesTask').
  - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'intermediateDir' without corresponding getter has been annotated with @OutputDirectory.
    
    Reason: Annotations on fields are only used if there's a corresponding getter for the field.
    
    Possible solutions:
      1. Add a getter for field 'intermediateDir'.
      2. Remove the annotations on 'intermediateDir'.
    
    Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
  - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'packageNameXOR1' without corresponding getter has been annotated with @Input.
    
    Reason: Annotations on fields are only used if there's a corresponding getter for the field.
    
    Possible solutions:
      1. Add a getter for field 'packageNameXOR1'.
      2. Remove the annotations on 'packageNameXOR1'.
    
    Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
  - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'packageNameXOR2' without corresponding getter has been annotated with @Input.
    
    Reason: Annotations on fields are only used if there's a corresponding getter for the field.
    
    Possible solutions:
      1. Add a getter for field 'packageNameXOR2'.
      2. Remove the annotations on 'packageNameXOR2'.
    
    Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
  - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'quickstartFile' without corresponding getter has been annotated with @InputFile, @Optional.
    
    Reason: Annotations on fields are only used if there's a corresponding getter for the field.
    
    Possible solutions:
      1. Add a getter for field 'quickstartFile'.
      2. Remove the annotations on 'quickstartFile'.
    
    Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.
  - In plugin 'com.google.gms.googleservices.GoogleServicesPlugin' type 'com.google.gms.googleservices.GoogleServicesTask' field 'searchedLocation' without corresponding getter has been annotated with @Input.
    
    Reason: Annotations on fields are only used if there's a corresponding getter for the field.
    
    Possible solutions:
      1. Add a getter for field 'searchedLocation'.
      2. Remove the annotations on 'searchedLocation'.
    
    Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#ignored_annotations_on_field for more details about this problem.

I've already tried:我已经尝试过:

  • Updated some dependencies outdated更新了一些过时的依赖项
  • Remove cordova-android-play-services-gradle-release cordova-android-support-gradle-release cordova-support-google-services删除cordova-android-play-services-gradle-release cordova-android-support-gradle-release cordova-support-google-services
  • Add in config.xmlconfig.xml添加
    <preference name="GradlePluginGoogleServicesEnabled" value="true" /> and <preference name="GradlePluginGoogleServicesEnabled" value="true" />
    <preference name="GradlePluginGoogleServicesVersion" value="4.3.8" />
    but when I did that, I've got another error:但是当我这样做时,我又遇到了另一个错误:
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.google.gms.google-services'.
   > Cannot add extension with name 'googleServices', as there is an extension already registered with that name.

Ionic CLI: 5.4.16离子 CLI:5.4.16
Ionic Framework: ionic-angular 3.9.8离子框架:离子角3.9.8
@ionic/app-scripts: 3.2.4 @ionic/app-scripts: 3.2.4

Cordova CLI: 10.0.0科尔多瓦 CLI:10.0.0
Cordova Platorms: android 10.1.1 Cordova 平台:安卓 10.1.1

NodeJS: 12.19.0 NodeJS:12.19.0
Android SDK Tools: 26.1.1 Android SDK 工具:26.1.1

Really big thanks for your question & description of the problem, because it helped me to upgrade from cordova-android 9.1.0 to 10.1.1 :-).非常感谢您的问题和对问题的描述,因为它帮助我从cordova-android 9.1.0 升级到10.1.1 :-)。

And i think i can solve your problem.我想我可以解决你的问题。 This error is thrown, because google services plugin is registered twice (apply plugin: 'com.google.gms.google-services') in gradle files, eg: platforms/android/app/build.gradle.抛出此错误,因为谷歌服务插件在 gradle 文件中注册了两次(应用插件:'com.google.gms.google-services'),例如:platforms/android/app/build.gradle。 You just have to comment/remove one of these imports.您只需要评论/删除这些导入之一。

Because cleaning files manually every time is very annoying, i created a bash script (= working on Mac OS), which comments the second import automatically: fix_android.sh因为每次手动清理文件很烦人,我创建了一个 bash 脚本(= 在 Mac OS 上工作),它会自动注释第二次导入: fix_android.sh

#!/usr/bin/env bash

echo "Executing fix_android.sh"

## comment duplicate import of com.google.gms.google-services plugin
#file=$(pwd)"/platforms/android/app/build.gradle"
file="platforms/android/app/build.gradle"
#echo ${file}
from="apply plugin: 'com.google.gms.google-services'"
to="\/\/apply plugin: 'com.google.gms.google-services'"

if [ -f "$file" ]; then
  if grep -lr "$to" "$file"; then
      echo "File already corrected!"
  else
      change=`sed "s/$from/$to/" < "$file"`
      echo "$change" > "$file"
      #echo "$change"
      echo "Commented duplicate import!"
  fi
else
  echo ${file}" not found!"
  ls -al platforms/android/app
fi

To start the script automatically before building, i use ionic building scripts/hooks in package.json :要在构建之前自动启动脚本,我在package.json 中使用了离子构建脚本/钩子:

"scripts": {
    ...
    "ionic:build:before": "./scripts/fix_android.sh",
    "ionic:build:after": "",
    ...

I also have the same build isuue from last 15 days.我也有过去 15 天相同的构建问题。 and i am unable to build my app can anyone found any solution?我无法构建我的应用程序 谁能找到任何解决方案?

In my case none of the provided answers were helpful.就我而言,提供的答案都没有帮助。 Take a look here config.xml-fix for the solution in config, maybe for somebody it will help.config.xml-fix 中查看config.xml-fix中的解决方案,也许对某些人会有所帮助。

I have 9.1.0 version of 'cordova-android' which is not supporting Android API 30+ Android API Levels and Android Versions我有 9.1.0 版本的“cordova-android”,它不支持 Android API 30+ Android API 级别和 Android 版本

How I fixed the issue OR how I hack the solution: Run:我如何解决问题或如何破解解决方案:运行:

  1. cordova platform rm android科尔多瓦平台rm android
  2. cordova platform add android科尔多瓦平台添加android

This should generate a "build.gradle" file in platforms\\android Then, manually change "project.ext" part of code and specify version which you want, in my case I need to support 30 API version:这应该在platforms\\android中生成一个“build.gradle”文件然后,手动更改代码的“project.ext”部分并指定你想要的版本,在我的情况下我需要支持30个API版本:

project.ext {
  defaultBuildToolsVersion="30.0.0" //String
  defaultMinSdkVersion=23 //Integer - Minimum requirement is Android 5.1
  defaultTargetSdkVersion=30 //Integer - We ALWAYS target the latest by default
  defaultCompileSdkVersion=30 //Integer - We ALWAYS compile with the latest by default
}

You can modify sh script proposed by @Mike for this needs.您可以针对此需求修改@Mike提出的 sh 脚本。

Btw, when i was trying to fix the issue on cordova-android version 10 - this block of code was even not presented in "build.gradle".顺便说一句,当我试图在cordova-android 10 版上解决这个问题时——这个代码块甚至没有出现在“build.gradle”中。

What protentionally could help too:什么也有帮助:

  1. Remove cordova-plugin-whitelist - it is not supported from version 10.删除 cordova-plugin-whitelist - 从版本 10 开始不支持它。
  2. In SDK Platforms manager - download needed API Level;在 SDK 平台管理器中 - 下载所需的 API 级别; 在此处输入图片说明
  3. In SDK Tools manager - download needed build tools version;在 SDK 工具管理器中 - 下载所需的构建工具版本; 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM