升级cordova-android 10后构建失败
Posted
技术标签:
【中文标题】升级cordova-android 10后构建失败【英文标题】:Build failing after upgrade cordova-android 10 【发布时间】:2021-12-19 17:02:03 【问题描述】:当我将cordova-android@9.0.0
升级到cordova-android@10.1.1
时,我在运行cordova build android --release --buildconfig=build.json
时遇到了构建问题
问题:
* 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" />
但是当我这样做时,我又遇到了另一个错误:
* 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 @ionic/app-scripts: 3.2.4 科尔多瓦 CLI:10.0.0 Cordova 平台:安卓 10.1.1 NodeJS:12.19.0 Android SDK 工具:26.1.1
【问题讨论】:
【参考方案1】:非常感谢您提出问题和对问题的描述,因为它帮助我从 cordova-android 9.1.0 升级到 10.1.1 :-)。
我想我可以解决你的问题。抛出此错误,因为 google 服务插件在 gradle 文件中注册了两次(应用插件:'com.google.gms.google-services'),例如:platforms/android/app/build.gradle .您只需评论/删除其中一个导入。
因为每次手动清理文件都很烦人,所以我创建了一个 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
为了在构建之前自动启动脚本,我在 package.json 中使用离子构建脚本/钩子:
"scripts":
...
"ionic:build:before": "./scripts/fix_android.sh",
"ionic:build:after": "",
...
这是我的实际项目和系统配置
【讨论】:
有趣...你知道是哪里/哪个插件导致了这个吗? (注册多个谷歌服务插件) 我在config.xml
中添加了<preference name="GradlePluginGoogleServicesVersion" value="4.3.8" />
并注释了重复的行,第二个错误已解决但第一个错误返回..
大约 2 个月前我在使用 cordova-support-google-services 插件时遇到了这个问题。插件本身似乎创建了 2 个导入。从 package.json 中删除 cordova-support-google-services 插件后,我在 config.xml 中添加了 2 个新的首选项标签并重新安装了所有软件包(没有 package-lock.json)以解决所有错误。顺便说一句,我本周使用 ionic cli 6.18.1 并升级到 angular 12.2.13 和 node.js 14.18.1。
问题解决了吗?如果对您有帮助,我可以将我的 config.xml 和 package.json 发送给您。您还必须在 config.xml 中将 android-targetSdkVersion 设置为 30,将 android-minSdkVersion 设置为 23。在我的准备工作中,我安装了 sdk build tools 30.0.3(因为 31.0.0 已损坏)并升级到 gradle 7.2。
完全没问题。很高兴听到你解决了你的问题,在你解决了我的问题之后 ;-)。【参考方案2】:
就我而言,提供的答案都没有帮助。 看看这里config.xml-fix 配置中的解决方案,也许对某人会有帮助。
我有 9.1.0 版本的 'cordova-android' 不支持 Android API 30+ Android API Levels and Android Versions
我如何解决问题或如何破解解决方案: 运行:
-
cordova 平台 rm android
cordova 平台添加 android
这应该在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
您可以根据需要修改@Mike提出的sh脚本。
顺便说一句,当我试图解决 cordova-android 版本 10 上的问题时 - 这段代码甚至没有出现在“build.gradle”中。
什么也可以提供帮助:
-
删除 cordova-plugin-whitelist - 版本 10 不支持它。
在 SDK 平台管理器中 - 下载所需的 API 级别;
在 SDK 工具管理器中 - 下载所需的构建工具版本;
【讨论】:
以上是关于升级cordova-android 10后构建失败的主要内容,如果未能解决你的问题,请参考以下文章
插件不支持该项目的 cordova-android 版本。 cordova-android:6.1.2,失败的版本要求:> = 6.3.0
在 Xcode 升级后 Flutter iOS 构建失败错误并带有多个命令
升级到 macOS Catalina 后使用 cmake 为 c++ 构建 opencv4 失败
使用冲突的 android 组件/依赖版本(play-services-location、firebase 等)构建 cordova-android
插件不支持该项目的 cordova-android 版本。 cordova-android:6.2.3,失败的版本要求:> = 6.3.0 in oracle MAF2.5