當我升級[email protected]到[email protected]運行時遇到構建問題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-releasecordova-android-support-gradle-releasecordova-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
離子框架:ionic-angular 3.9.8
@ionic/app-scripts:3.2.4
Cordova CLI:10.0.0
Cordova Platorms:android 10.1.1
NodeJS:12.19.0
Android SDK 工具:26.1.1
uj5u.com熱心網友回復:
非常感謝您的問題和對問題的描述,因為它幫助我從cordova-android 9.1.0 升級到10.1.1 :-)。
我想我可以解決你的問題。拋出此錯誤,因為谷歌服務插件在 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": "",
...
這是我的實際專案和系統配置

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/358655.html
上一篇:CordovaAndroid構建錯誤:“:app:processReleaseGoogleServices'(型別'GoogleServicesTask')”
