Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android-targetSdkVersion 34 not working: Google Play Console reads 33, Cordova reads 34 #1729

Closed
3 tasks done
cyril23 opened this issue Aug 1, 2024 · 2 comments
Closed
3 tasks done
Labels
info-needed / awaiting response Further information is requested

Comments

@cyril23
Copy link

cyril23 commented Aug 1, 2024

Bug Report

Problem

What is expected to happen?

  • Google Play Console recognizes apps built via <preference name="android-targetSdkVersion" value="34" /> as target SDK 34 (Android 14)

What does actually happen?

  • Google Play Console recognizes my app which includes <preference name="android-targetSdkVersion" value="34" /> within the config.xml as target SDK 33 instead of 34. I've build version 18.26.0 today, see full config.xml and build log below.
    image

  • I already saw the same problem in my older release 18.25.4 from a week ago, too, which already included the same config.xml: image - so it is not a thing which just goes away after waiting a few days.

  • The problem I have is that I need to use SDK 34 starting 31. August 2024 to publish any app updates, see https://support.google.com/googleplay/android-developer/answer/11926878

Information

  • config.xml: config.xml.txt
    • I hope my minSdkVersion is not set too low?
	<preference name="android-minSdkVersion" value="22" />
	<preference name="android-targetSdkVersion" value="34" />

Using cordova-fetch for cordova-android@13.0.0
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: de.yyy.XXX.myapp
Name: my-app
Activity: MainActivity
Android Target SDK: android-34
Android Compile SDK: 34
Subproject Path: CordovaLib
Subproject Path: app
Android project created with cordova-android@13.0.0

Command or Code

Environment, Platform, Device

  • building on Mac mini 2018, macOS Sonoma 14.1.2, see image

Version information

  • Cordova CLI:

cordova --version
12.0.0 (cordova-lib@12.0.1)

  • Platform: cordova platform add android@13.0.0
  • Plugins: see config.xml above
  • Operating System: see above
  • Android Studio: Android Studio Dolphin, 2021.3.1 Patch 1, see image. My Android SDK settings within Android Studio: see image and image
  • Xcode: 15.2 (15C500b), see image

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Hints

  • in file platforms\android\app\build\outputs\logs\manifest-merger-debug-report.txt I can see this:
MERGED from [com.huawei.hms:ucs-common:1.0.3.323] /Users/xx/.gradle/caches/transforms-4/fca4ef79003ed3d48602d89c9c27e186/transformed/jetified-ucs-common-1.0.3.323/AndroidManifest.xml:5:5-7:41
	tools:overrideLibrary
		ADDED from [com.huawei.hms:device:6.5.0.300] /Users/xx/.gradle/caches/transforms-4/0b74e76dedf911529828956725343c5f/transformed/jetified-device-6.5.0.300/AndroidManifest.xml:9:9-58
	android:targetSdkVersion
		INJECTED from /Users/xx/Desktop/cordova/myapp.native.20240801-154436/platforms/android/app/src/main/AndroidManifest.xml
	android:minSdkVersion
		INJECTED from /Users/xx/Desktop/cordova/myapp.native.20240801-154436/platforms/android/app/src/main/AndroidManifest.xml
uses-permission#android.permission.WAKE_LOCK
ADDED from [com.transistorsoft:tslocationmanager:3.5.4] /Users/xx/.gradle/caches/transforms-4/d18416e1d05ee88a7c27b8d8f1508082/transformed/jetified-tslocationmanager-3.5.4/AndroidManifest.xml:7:5-68
  • in platforms\android\CordovaLib\build\outputs\logs\manifest-merger-debug-report.txt I see something similar: manifest-merger-blame-debug-report.txt
  • but in platforms\android\app\src\main\AndroidManifest.xml I cannot find any targetSdkVersion, see AndroidManifext.xml.txt
  • strangely in platforms\android\app\build\intermediates\merged_manifest\debug\processDebugMainManifest\AndroidManifest.xml it looks like something was overriding or "injecting" another targetSdkVersion, and therefore I get a 33 instead of 34 here (see processDebugMainManifest_AndroidManifest.xml.txt):
    android:versionCode="1182600"
    android:versionName="18.26.0" >

    <uses-sdk
        android:minSdkVersion="22"
        android:targetSdkVersion="33" />
@breautek
Copy link
Contributor

breautek commented Aug 1, 2024

Firstly, thanks for the detailed report. It helps quickly rule out A LOT of potential causes.

cordova-android@13 by default targets API 34. But given that even after explicitly using the preference the build is still producing an API 33 target leads me to believe that there is a plugin or something overriding.

I cannot find any targetSdkVersion, see

This is because SDK stuff is no longer set in AndroidManifest.xml directly. It's configured in gradle build scripts instead. The gradle build will merge in the configurations (which back in the day were manually set in AndroidManifest.xml), hence why you see it in the intermediates merged manifest's build artefact.

If you're able to open the project in Android Studio, look at your AndroidManifest and use the Merged Manifest tab, you'll see the <uses-sdk> directive which is what the current state of the project will produce on build after all the merges occur. You'll also see a window of all the sources used to produce the merged manifest.

Unfortunately the merged manifest while does link to manifest sources, including gradle files, it doesn't really point to you where the exact source is, so some digging will still be required.

Cordova projects will have a config that looks like this in the app's build.gradle:

defaultConfig {
        versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
        applicationId cordovaConfig.PACKAGE_NAMESPACE

        minSdkVersion cordovaConfig.MIN_SDK_VERSION
        if (cordovaConfig.MAX_SDK_VERSION != null) {
            maxSdkVersion cordovaConfig.MAX_SDK_VERSION
        }
        targetSdkVersion cordovaConfig.SDK_VERSION
        compileSdkVersion cordovaConfig.COMPILE_SDK_VERSION
    }

And the cordovaConfig values will be sourced from /platforms/android/cdv-gradle-config.json

So I would:

  1. Double check that the defaultConfig is in tact (inside /platforms/android/app/build.gradle) and especially for the targetSdkVersion cordovaConfig.SDK_VERSION.
  2. Double check the cdv-gradle-config.json file and ensure that it contains "SDK_VERSION": 34 in it. If it's some other value, like 33 then it means something is overriding the preference somehow, or for some reason, or the json file is simply not being updated for some reason.
  3. If the above looks right/ok, then it would be time to start scanning the gradle files, especially any custom ones that plugins might be introducing to see if they were defining a targetSdk or targetSdkVersion (they both do the same thing, I believe one of them is deprecated).

I'm pretty confident that Cordova itself is behaving correctly, based on my own personal usages of Cordova. So I'd be pretty surprise if the issue is within the Cordova framework itself... This isn't an issue I've yet to see so that's why I'm pretty suspicious of a misbehaving plugin setting the target SDK, potentially overriding the application (since plugins becomes part of the application).

Let me know if this helps or what you find.

@breautek breautek added the info-needed / awaiting response Further information is requested label Aug 1, 2024
@cyril23
Copy link
Author

cyril23 commented Aug 2, 2024

I've got it: i had included a gradle file myself (it was not a plugin!) which enforces sdk 33...

Thanks for your quick reply! I've found my mistake: Not a long time ago I've included a file named build-extras.gradle in my ressource folder www/res/build-extras.gradle (that I already completely forgot about!), containing just these 2 lines:

ext.cdvSdkVersion=33
ext.cdvCompileSdkVersion=33

I've included that in my project within config.xml as follows:

<platform name="android">
	<resource-file src="www/google-services.json" target="/app/google-services.json" />
	<resource-file src="www/res/icon/android/pw_notification.png" target="app/src/main/res/drawable/pw_notification.png"/>
	<resource-file src="www/res/build-extras.gradle" target="/app/build-extras.gradle"/>
</platform>

SOLUTION: I just need to remove that file (both the ressource file and the <resource-file reference within config.xml of course)

Background of why I included that file in the past

Just for the record: I have included that file according to https://cordova.apache.org/docs/en/12.x/guide/platforms/android/#configuring-gradle when trying to fix an issue I had with a plugin cordova-background-geolocation (from transistorsoft) before:

1: Task failed with an exception.
-----------
* Where:
Script 'xxx/platforms/android/cordova-background-geolocation/myapp-build.gradle' line: 123

* What went wrong:
A problem occurred evaluating script.
> Cannot invoke method split() on null object

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* 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.

So I've tried fixing that issue in the past by creating that build-extras.gradle file, but completely forgot about it ...

The actual fix to the compile time exception Task failed with an exception was something completely different: the myapp-build.gradle' line: 123 referred to a problem that the GOOGLE_API_VERSION definition was missing in my config.xml. The fix was inserting the following to the config.xml:

<plugin name="cordova-background-geolocation" spec="https://github.com/transistorsoft/cordova-background-geolocation.git#4.16.5">
	<variable name="GOOGLE_API_VERSION" value="20.+" /> <!-- 4.13.0+ requires definition of GOOGLE_API_VERSION here or via CLI param see https://github.com/transistorsoft/cordova-background-geolocation?tab=readme-ov-file#variable-google_api_version-20 -->
	<variable name="HMS_LOCATION_VERSION" value="6.11.0.301" /> <!-- 4.13.0+ requires this, prevents "Could not find com.huawei.hms:location:null" see https://github.com/transistorsoft/cordova-background-geolocation/issues/2381#issuecomment-1686963433 -->
	<variable name="OKHTTP_VERSION" value="3.12.+" />
	<variable name="EVENTBUS_VERSION" value="3.3.1" />
	<variable name="BACKGROUND_MODE_LOCATION" value="<string>location</string>" />
</plugin>

So that's why I can safely remove my custom build-extras.gradle file now (or just remove its contents).

(not needed anymore: my responses to your hints)

before finding the solution to this issue, I've provided some answers to your hints, so I'll just leave them here:

If you're able to open the project in Android Studio, look at your AndroidManifest and use the Merged Manifest tab, you'll see the directive which is what the current state of the project will produce on build after all the merges occur. You'll also see a window of all the sources used to produce the merged manifest.

I've never worked with Android Studio (except for downloading the SDK), because I don't have an Android project but just work with cordova. I just opened the folder of all my Cordova files within Android Studio, but don't know where to find the AndroidManifest. I've checked https://stackoverflow.com/questions/4191762/how-to-view-androidmanifest-xml-from-apk-file which describes how to get the Manifest from bundled apks. I have the apk files too of course, but the android sdk apkanalyzer crashed: running Build -> Analyze APK -> selecting either debug or release apks -> nothing happens.. somehow it crashed obviously, so I've tried the command line tool directly:

Mac-mini:~ xx$ /Users/xx/Library/Android/sdk/tools/bin/apkanalyzer manifest print Desktop/app-release.apk 
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
	at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
	at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
	at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
	at com.android.tools.apk.analyzer.ApkAnalyzerCli.getAaptInvokerFromSdk(ApkAnalyzerCli.java:277)
	at com.android.tools.apk.analyzer.ApkAnalyzerCli.main(ApkAnalyzerCli.java:129)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	... 5 more
Mac-mini:~ xx$ /Users/xx/Library/Android/sdk/tools/bin/apkanalyzer manifest print Desktop/app-debug.apk 
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
	at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
	at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
	at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
	at com.android.tools.apk.analyzer.ApkAnalyzerCli.getAaptInvokerFromSdk(ApkAnalyzerCli.java:277)
	at com.android.tools.apk.analyzer.ApkAnalyzerCli.main(ApkAnalyzerCli.java:129)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	... 5 more
Mac-mini:~ xx$ 

Double check that the defaultConfig is in tact (inside /platforms/android/app/build.gradle) and especially for the targetSdkVersion cordovaConfig.SDK_VERSION.

android {
    namespace cordovaConfig.PACKAGE_NAMESPACE

    buildFeatures {
        buildConfig true
    }

    defaultConfig {
        versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
        applicationId cordovaConfig.PACKAGE_NAMESPACE

        minSdkVersion cordovaConfig.MIN_SDK_VERSION
        if (cordovaConfig.MAX_SDK_VERSION != null) {
            maxSdkVersion cordovaConfig.MAX_SDK_VERSION
        }
        targetSdkVersion cordovaConfig.SDK_VERSION
        compileSdkVersion cordovaConfig.COMPILE_SDK_VERSION
    }

see full platforms\android\app\build.gradle file: platforms_android_app_build.gradle.txt

maybe this section is interesting from the platforms\android\app\build.gradle file:

// PLUGIN GRADLE EXTENSIONS START
apply from: "../cordova-plugin-background-fetch/myapp-build.gradle"
apply from: "../cordova-background-geolocation/myapp-build.gradle"
apply from: "../cordova-plugin-enable-multidex/myapp-build.gradle"
apply from: "../phonegap-plugin-barcodescanner/myapp-barcodescanner.gradle"
apply from: "../pushwoosh-cordova-plugin/myapp-build-extras-pushwoosh.gradle"
// PLUGIN GRADLE EXTENSIONS END

and maybe this is interesting too:

    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: ":CordovaLib"))
    implementation "androidx.lifecycle:lifecycle-runtime:2.4.+"
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.+"
    implementation "com.squareup.okhttp3:okhttp:3.12.+"
    implementation "org.greenrobot:eventbus:3.3.1"
    implementation "io.github.nishkarsh:android-permissions:2.1.6"
    implementation "org.slf4j:slf4j-api:2.0.7"
    implementation "com.github.tony19:logback-android:3.0.0"
    implementation "androidx.core:core:1.6.+"
    implementation "androidx.webkit:webkit:1.4.0"
    implementation "com.android.support:support-v4:27.+"
    implementation "androidx.work:work-runtime:2.7.1"
    implementation "androidx.annotation:annotation:1.4.0"
    implementation "androidx.appcompat:appcompat:1.4.0"
    implementation "androidx.recyclerview:recyclerview:1.2.1"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation "com.github.bumptech.glide:glide:4.10.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.60"
    implementation "com.pushwoosh:pushwoosh:6.7.7"
    implementation "com.pushwoosh:pushwoosh-amazon:6.7.7"
    implementation "com.pushwoosh:pushwoosh-firebase:6.7.7"
    implementation "com.pushwoosh:pushwoosh-badge:6.7.7"
    implementation "com.pushwoosh:pushwoosh-inbox:6.7.7"
    implementation "com.pushwoosh:pushwoosh-inbox-ui:6.7.7"
    implementation "com.pushwoosh:pushwoosh-huawei:6.7.7"
    // SUB-PROJECT DEPENDENCIES END

Double check the cdv-gradle-config.json file and ensure that it contains "SDK_VERSION": 34 in it

{
	"MIN_SDK_VERSION": 22,
	"SDK_VERSION": 34,
	"COMPILE_SDK_VERSION": null,
	"GRADLE_VERSION": "8.7",
	"MIN_BUILD_TOOLS_VERSION": "34.0.0",
	"AGP_VERSION": "8.3.0",
	"KOTLIN_VERSION": "1.9.24",
	"ANDROIDX_APP_COMPAT_VERSION": "1.6.1",
	"ANDROIDX_WEBKIT_VERSION": "1.6.0",
	"ANDROIDX_CORE_SPLASHSCREEN_VERSION": "1.0.0",
	"GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION": "4.3.15",
	"IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED": true,
	"IS_GRADLE_PLUGIN_KOTLIN_ENABLED": false,
	"PACKAGE_NAMESPACE": "de.xxx.yyy.myapp",
	"JAVA_SOURCE_COMPATIBILITY": 8,
	"JAVA_TARGET_COMPATIBILITY": 8,
	"KOTLIN_JVM_TARGET": null
}

looks fine

If the above looks right/ok, then it would be time to start scanning the gradle files, especially any custom ones that plugins might be introducing to see if they were defining a targetSdk or targetSdkVersion (they both do the same thing, I believe one of them is deprecated).

At first I'll check all files named *gradle* which do contain targetSdk. Only 4 hits:

def doVerifyCordovaConfigForBuild() {
    if (cordovaConfig.COMPILE_SDK_VERSION < cordovaConfig.SDK_VERSION) {
        println "The \"compileSdkVersion\" (${cordovaConfig.COMPILE_SDK_VERSION}) should be greater than or equal to the the \"targetSdkVersion\" (${cordovaConfig.SDK_VERSION})."
    }
}
  • platforms\android\app\build.gradle see above
  • node_modules\cordova-android\templates\project\app\build.gradle is similar to platforms\android\app\build.gradle, but without the plugins (I showed the differences between the two files above in the "interesting" sections), see full file node_modules_cordova-android_templates_project_app_build.gradle.txt

@cyril23 cyril23 closed this as completed Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed / awaiting response Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants