cyril23 commented on issue #1729:
URL: 
https://github.com/apache/cordova-android/issues/1729#issuecomment-2265824899

   ## 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 <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.
   
   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](https://github.com/user-attachments/files/16472516/patforms_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:
   - `node_modules\cordova-android\framework\cordova.gradle` is identical to 
file `platforms\android\CordovaLib\cordova.gradle`  and they only contain 
`targetSdk` here (see 
[platforms_android_CordovaLib_cordova.gradle.txt](https://github.com/user-attachments/files/16472866/platforms_android_CordovaLib_cordova.gradle.txt)):
   ```
   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](https://github.com/user-attachments/files/16472613/node_modules_cordova-android_templates_project_app_build.gradle.txt)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to