I've searched through all of the answers I can find on stack overflow as well as on other similar sites, but the solutions there do not solve my problem.
I am trying to update my build tools on an old project from sdk 28 to sdk 31, to comply with the Google Play Store's security requirements, but every time I run ionic cordova build android --stacktrace
I get the following result:
Dependency classpath 'com.google.gms:google-services:4.3.10' already exist
cordova-plugin-androidx-adapter: Processed 69 Java source files in 1010ms
cordova-plugin-firebasex: Preparing Firebase on Android
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/opt/android-sdk (recommended setting)
ANDROID_HOME=/opt/android-sdk (DEPRECATED)
Using Android SDK: /opt/android-sdk
Subproject Path: CordovaLib
Subproject Path: app
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
> Configure project :app
WARNING:: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed in version 7.0 of the Android Gradle plugin.
For more information, see http://d.android.com/r/tools/update-dependency-configurations.html.
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
WARNING:: API 'variant.getMappingFile()' is obsolete and has been replaced with 'variant.getMappingFileProvider()'.
It will be removed in version 7.0 of the Android Gradle plugin.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getMappingFile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
> Task :app:processDebugGoogleServices FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Some problems were found with the configuration of task ':app:processDebugGoogleServices' (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.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 14s
9 actionable tasks: 1 executed, 8 up-to-date
Command failed with exit code 1: /home/koseward/Desktop/iMATter/iMATterMobile/platforms/android/gradlew cdvBuildDebug -b /home/koseward/Desktop/iMATter/iMATterMobile/platforms/android/build.gradle
According to other answers, this seems to mean that I am using an old version of the com.google.gms:google-services:4.3.10
plugin, but I can't find where that is being called.
What I've tried:
- Adding
ext{ GOOGLE_SERVICES_VERSION='4.3.10'}
to my globalallProjects
build.gradle. This didn't change the result - Commenting the
apply plugin: 'com.google.gms.google-services'
line in the local build.gradle. This changed the error message fromCannot add extension with name 'googleServices', as there is an extension already registered with that name.
to the error shown above. This also was tried in a similar block in build.gradle that will be shown below. - I added
<preference name="GradlePluginGoogleServicesVersion" value="4.3.14" />
and<preference name="AndroidXEnabled" value="true" />
to config.xml. This seems to have standardize the version number, but does not fix the problem. - I removed and re-added android with
ionic cordova platform remove android
andionic cordova platform add android
but this reset did not change the issues - Changing the version of
classpath 'com.google.gms:google-services:4.3.10'
in both /platforms/android/build.gradle and /platforms/android/app/build.gradle. I am confused about this one because each time I try to build, it changes back or duplicates with the old version, but I cannot figure out where this is coming from. - Ensuring the google-services.json has all necessary information. I have downloaded and redownloaded this file from firebase and it has not changed the outcome.
/platforms/android build.gradle:
buildscript {
apply from: 'CordovaLib/cordova.gradle'
apply from: 'repositories.gradle'
repositories repos
dependencies {
classpath "com.android.tools.build:gradle:${cordovaConfig.AGP_VERSION}"
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${cordovaConfig.KOTLIN_VERSION}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
def hasRepositoriesGradle = file('repositories.gradle').exists()
if (hasRepositoriesGradle) {
apply from: 'repositories.gradle'
} else {
apply from: "${project.rootDir}/repositories.gradle"
}
repositories repos
}
task clean(type: Delete) {
delete rootProject.buildDir
}
/platforms/android/app build.gradle:
apply plugin: 'com.android.application'
if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
}
buildscript {
apply from: '../CordovaLib/cordova.gradle'
// Checks if the kotlin version format is valid.
if(cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
if(!cdvHelpers.isVersionValid(cordovaConfig.KOTLIN_VERSION)) {
throw new GradleException("The defined Kotlin version (${cordovaConfig.KOTLIN_VERSION}) does not appear to be a valid version.")
}
}
apply from: 'repositories.gradle'
repositories repos
dependencies {
classpath "com.android.tools.build:gradle:${cordovaConfig.AGP_VERSION}"
if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${cordovaConfig.KOTLIN_VERSION}"
}
if(cordovaConfig.IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED) {
// Checks if the kotlin version format is valid.
if(!cdvHelpers.isVersionValid(cordovaConfig.GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION)) {
throw new GradleException("The defined Google Services plugin version (${cordovaConfig.GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION}) does not appear to be a valid version.")
}
// Create the Google Services classpath and set it.
String gradlePluginGoogleServicesClassPath = "com.google.gms:google-services:${cordovaConfig.GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION}"
println "Adding classpath: ${gradlePluginGoogleServicesClassPath}"
classpath gradlePluginGoogleServicesClassPath
}
}
}
// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
def hasRepositoriesGradle = file('repositories.gradle').exists()
if (hasRepositoriesGradle) {
apply from: 'repositories.gradle'
} else {
apply from: "${project.rootDir}/repositories.gradle"
}
repositories repos
}
task wrapper(type: Wrapper) {
gradleVersion = cordovaConfig.GRADLE_VERSION
}
// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
ext {
apply from: '../CordovaLib/cordova.gradle'
// Sets the versionCode to the given value.
if (!project.hasProperty('cdvVersionCode')) {
cdvVersionCode = null
}
// Whether to build architecture-specific APKs.
if (!project.hasProperty('cdvBuildMultipleApks')) {
cdvBuildMultipleApks = null
}
// Whether to append a 0 "abi digit" to versionCode when only a single APK is build
if (!project.hasProperty('cdvVersionCodeForceAbiDigit')) {
cdvVersionCodeForceAbiDigit = null
}
// .properties files to use for release signing.
if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
cdvReleaseSigningPropertiesFile = null
}
// .properties files to use for debug signing.
if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
cdvDebugSigningPropertiesFile = null
}
// Set by build.js script.
if (!project.hasProperty('cdvBuildArch')) {
cdvBuildArch = null
}
// Plugin gradle extensions can append to this to have code run at the end.
cdvPluginPostBuildExtras = []
}
// PLUGIN GRADLE EXTENSIONS START
apply from: "../cordova-plugin-badge/iMATter-badge.gradle"
apply from: "../cordova-plugin-enable-multidex/iMATter-build.gradle"
apply from: "../cordova-plugin-firebasex/iMATter-build.gradle"
apply from: "../cordova-plugin-local-notification/iMATter-localnotification.gradle"
// PLUGIN GRADLE EXTENSIONS END
def hasBuildExtras1 = file('build-extras.gradle').exists()
if (hasBuildExtras1) {
apply from: 'build-extras.gradle'
}
def hasBuildExtras2 = file('../build-extras.gradle').exists()
if (hasBuildExtras2) {
apply from: '../build-extras.gradle'
}
// Apply updates that might come from build-extra.
privateHelpers.applyCordovaConfigCustomization()
// Set property defaults after extension .gradle files.
if (ext.cdvDebugSigningPropertiesFile == null && file('../debug-signing.properties').exists()) {
ext.cdvDebugSigningPropertiesFile = '../debug-signing.properties'
}
if (ext.cdvReleaseSigningPropertiesFile == null && file('../release-signing.properties').exists()) {
ext.cdvReleaseSigningPropertiesFile = '../release-signing.properties'
}
// Cast to appropriate types.
ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
ext.cdvVersionCodeForceAbiDigit = cdvVersionCodeForceAbiDigit == null ? false : cdvVersionCodeForceAbiDigit.toBoolean();
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' cdvVersionCode)
def computeBuildTargetName(debugBuild) {
def ret = 'assemble'
if (cdvBuildMultipleApks && cdvBuildArch) {
def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
ret = '' arch.toUpperCase().charAt(0) arch.substring(1);
}
return ret (debugBuild ? 'Debug' : 'Release')
}
// Make cdvBuild a task that depends on the debug/arch-sepecific task.
task cdvBuildDebug
cdvBuildDebug.dependsOn {
return computeBuildTargetName(true)
}
task cdvBuildRelease
cdvBuildRelease.dependsOn {
return computeBuildTargetName(false)
}
task cdvPrintProps {
doLast {
println('cdvBuildToolsVersion=' cdvBuildToolsVersion)
println('cdvVersionCode=' cdvVersionCode)
println('cdvVersionCodeForceAbiDigit=' cdvVersionCodeForceAbiDigit)
println('cdvSdkVersion=' cdvSdkVersion)
println('cdvMinSdkVersion=' cdvMinSdkVersion)
println('cdvMaxSdkVersion=' cdvMaxSdkVersion)
println('cdvBuildMultipleApks=' cdvBuildMultipleApks)
println('cdvReleaseSigningPropertiesFile=' cdvReleaseSigningPropertiesFile)
println('cdvDebugSigningPropertiesFile=' cdvDebugSigningPropertiesFile)
println('cdvBuildArch=' cdvBuildArch)
println('computedVersionCode=' android.defaultConfig.versionCode)
println('cdvAndroidXAppCompatVersion=' cdvAndroidXAppCompatVersion)
println('cdvAndroidXWebKitVersion=' cdvAndroidXWebKitVersion)
android.productFlavors.each { flavor ->
println('computed' flavor.name.capitalize() 'VersionCode=' flavor.versionCode)
}
}
}
android {
defaultConfig {
versionCode cdvVersionCode ?: new BigInteger("" privateHelpers.extractIntFromManifest("versionCode"))
applicationId privateHelpers.extractStringFromManifest("package")
minSdkVersion cordovaConfig.MIN_SDK_VERSION
if (cordovaConfig.MAX_SDK_VERSION != null) {
maxSdkVersion cordovaConfig.MAX_SDK_VERSION
}
targetSdkVersion cordovaConfig.SDK_VERSION
compileSdkVersion cordovaConfig.SDK_VERSION
}
lintOptions {
abortOnError false
}
buildToolsVersion cordovaConfig.BUILD_TOOLS_VERSION
// This code exists for Crosswalk and other Native APIs.
// By default, we multiply the existing version code in the
// Android Manifest by 10 and add a number for each architecture.
// If you are not using Crosswalk or SQLite, you can
// ignore this chunk of code, and your version codes will be respected.
if (Boolean.valueOf(cdvBuildMultipleApks)) {
flavorDimensions "default"
productFlavors {
armeabi {
versionCode defaultConfig.versionCode*10 1
ndk {
abiFilters = ["armeabi"]
}
}
armv7 {
versionCode defaultConfig.versionCode*10 2
ndk {
abiFilters = ["armeabi-v7a"]
}
}
arm64 {
versionCode defaultConfig.versionCode*10 3
ndk {
abiFilters = ["arm64-v8a"]
}
}
x86 {
versionCode defaultConfig.versionCode*10 4
ndk {
abiFilters = ["x86"]
}
}
x86_64 {
versionCode defaultConfig.versionCode*10 5
ndk {
abiFilters = ["x86_64"]
}
}
}
} else if (Boolean.valueOf(cdvVersionCodeForceAbiDigit)) {
// This provides compatibility to the default logic for versionCode before cordova-android 5.2.0
defaultConfig {
versionCode defaultConfig.versionCode*10
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
if (cdvReleaseSigningPropertiesFile) {
signingConfigs {
release {
// These must be set or Gradle will complain (even if they are overridden).
keyAlias = ""
keyPassword = ""
storeFile = null
storePassword = ""
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
}
if (cdvDebugSigningPropertiesFile) {
addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
}
sourceSets {
main.java.srcDirs = 'src/main/kotlin'
}
}
/*
* WARNING: Cordova Lib and platform scripts do management inside of this code here,
* if you are adding the dependencies manually, do so outside the comments, otherwise
* the Cordova tools will overwrite them
*/
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
implementation "androidx.appcompat:appcompat:${cordovaConfig.ANDROIDX_APP_COMPAT_VERSION}"
if (cordovaConfig.IS_GRADLE_PLUGIN_KOTLIN_ENABLED) {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${cordovaConfig.KOTLIN_VERSION}"
}
// SUB-PROJECT DEPENDENCIES START
implementation(project(path: ":CordovaLib"))
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "com.google.android.gms:play-services-tagmanager:17.0.0"
implementation "com.google.android.gms:play-services-auth:17.0.0"
implementation "com.google.firebase:firebase-analytics:17.2.1"
implementation "com.google.firebase:firebase-messaging:20.0.0"
implementation "com.google.firebase:firebase-config:19.0.3"
implementation "com.google.firebase:firebase-perf:19.0.1"
implementation "com.google.firebase:firebase-auth:19.1.0"
implementation "com.google.firebase:firebase-inappmessaging-display:19.0.3"
implementation "com.google.firebase:firebase-firestore:21.4.0"
implementation "com.crashlytics.sdk.android:crashlytics:2.10.1"
implementation "com.crashlytics.sdk.android:crashlytics-ndk:2.1.1"
implementation "com.google.code.gson:gson:2.8.6"
implementation "androidx.annotation:annotation:1.0.0"
implementation "com.google.gms:google-services:4.3.10"
implementation "com.google.firebase:firebase-messaging:20.0.1"
implementation "androidx.legacy:legacy-support-v13:1.0.0"
implementation "me.leolin:ShortcutBadger:1.1.17@aar"
implementation "com.google.firebase:firebase-messaging:18. "
// SUB-PROJECT DEPENDENCIES END
}
def addSigningProps(propsFilePath, signingConfig) {
def propsFile = file(propsFilePath)
def props = new Properties()
propsFile.withReader { reader ->
props.load(reader)
}
def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))
if (!storeFile.isAbsolute()) {
storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())
}
if (!storeFile.exists()) {
throw new FileNotFoundException('Keystore file does not exist: ' storeFile.getAbsolutePath())
}
signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')
signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))
signingConfig.storeFile = storeFile
signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
def storeType = props.get('storeType', props.get('key.store.type', ''))
if (!storeType) {
def filename = storeFile.getName().toLowerCase()
if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
storeType = 'pkcs12'
} else {
storeType = signingConfig.storeType // "jks"
}
}
signingConfig.storeType = storeType
}
for (def func : cdvPluginPostBuildExtras) {
func()
}
// This can be defined within build-extras.gradle as:
// ext.postBuildExtras = { ... code here ... }
if (hasProperty('postBuildExtras')) {
postBuildExtras()
}
// if (cordovaConfig.IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED) {
// apply plugin: 'com.google.gms.google-services'
// }
I guess my main question is this: how do I ensure that I am using the right version of google-services?
I know this is old stuff, but I am hoping that by compiling all of the answers I have found and tried into one place, I can help someone else out who is trying to update an old app.
CodePudding user response:
Basically, my solution was a reinstall. To solve, I simply did a fresh install of the project, on a new branch and started over. I also did a fresh install of my build tools, but I don't think this had any major effect on the result. I then changed the target SDK to 32, enabled android X, and updated some of my older Cordova plugins.