首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >升级cordova-android 10后生成失败

升级cordova-android 10后生成失败
EN

Stack Overflow用户
提问于 2021-11-05 16:51:26
回答 2查看 5.3K关注 0票数 8

当我将cordova-android@9.0.0升级到cordova-android@10.1.1时,我在运行cordova build android --release --buildconfig=build.json时遇到了构建问题

问题:

代码语言:javascript
复制
* 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.

我已经试过了

  • 更新了一些过时的依赖项
  • 删除cordova-android-play-services-gradle-release cordova-android-support-gradle-release cordova-support-google-services
  • 添加config.xml <preference name="GradlePluginGoogleServicesEnabled" value="true" /><preference name="GradlePluginGoogleServicesVersion" value="4.3.8" /> 但当我这么做的时候,我又犯了一个错误:
代码语言:javascript
复制
* 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.

离子CLI: 5.4.16

离子框架:离子角3.9.8

@离子型/应用程序-脚本: 3.2.4

Cordova CLI: 10.0.0

Cordova Platorms: android 10.1.1

NodeJS: 12.19.0

Android工具: 26.1.1

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-11-11 10:37:53

非常感谢您对这个问题的提问和描述,因为它帮助我从cordova-android 9.1.0升级到10.1.1 :-)。

我想我能解决你的问题。引发此错误,因为google服务插件在gradle文件中注册了两次(应用插件:‘com.google.gms.google-’),例如: platforms/android/app/build.gradle。您只需注释/删除其中一个导入即可。

因为每次手动清理文件都很烦人,所以我创建了一个bash脚本(=在Mac上工作),它自动地注释第二个导入:fix_android.sh

代码语言:javascript
复制
#!/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

要在构建之前自动启动脚本,我在package.json中使用离子构建脚本/钩子。

代码语言:javascript
复制
"scripts": {
    ...
    "ionic:build:before": "./scripts/fix_android.sh",
    "ionic:build:after": "",
    ...

这是我的实际项目和系统配置。

票数 2
EN

Stack Overflow用户

发布于 2021-11-25 12:51:55

就我而言,所提供的任何答案都没有帮助。看看这里的config.xml-fix,了解配置中的解决方案,也许对某些人会有帮助。

我有9.1.0版的“cordova- Android”,它不支持Android 30+ Android API级别和Android版本

如何解决问题或如何破解解决方案:运行:

  1. cordova平台rm android
  2. cordova平台添加android

这将在平台\android中生成一个"build.gradle“文件,然后手动更改代码的"project.ext”部分,并指定您想要的版本,在我的示例中,我需要支持30个API版本:

代码语言:javascript
复制
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
}

您可以修改@Mike提出的sh脚本以满足这一需求。

顺便说一下,当我试图在cordova-android版本10上解决这个问题时,这段代码甚至没有在"build.gradle“中出现。

从本质上来说,什么也能起到帮助作用:

  1. 删除科多瓦-插件-白名单-它不支持从版本10。
  2. 在SDK平台管理器-下载所需的API级别;

  1. 在SDK工具管理器-下载所需的构建工具版本;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69856650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档