6

I'm new to android application building using cordova-android.

I'm facing issue when updating compileSdkVersion/buildToolsVersion in config.xml of project root directory.

As cordova-android version-9 support api level 29 but as Android SDK API level 30 is available and cordova-android still not provided support yet.

I tried updating preferences compileSdkVersion/buildToolsVersion like below in config.xml

<?xml version='1.0' encoding='utf-8'?>
My first app Test application Your Name Here

Can someone help me in updating above two properties, so that apk can be build with latest SDK API level 30.

user2313833
  • 139
  • 1
  • 2
  • 14

3 Answers3

8

Based on Cordova requirements and support, current cordova-android@9 supports API level 29 and below. We can expect that next version cordova-android@10 will likely to target API level 30 and may need to wait for an official update from Cordova team. enter image description here

Until then we can play around with the nightly version of cordova-android@10 from npm

According to the recent deadlines from Google,

August 2021 - New apps must target at least Android 11 (API level 30)

November 2021 - Existing apps must target at least Android 11 (API level 30) for new app updates

So we can wait till August for an official update :).

Workaround :
(may or may not work. Use it in a sample application before implementing in the real application)

Change android-targetSdkVersion on config.xml

<preference name="android-targetSdkVersion" value="30" />

Remove the platform by using

cordova platform remove android

then add the latest cordova android version :

cordova platform add android@latest

Build the project :

cordova build android
Swaminathan V
  • 4,663
  • 2
  • 22
  • 32
  • 2
    Above approach didn't upgraded to latest android sdk version(api level 30), as cordova-android latest official version is 9.1.0 and below is the gradle properties it created. `project.ext { defaultBuildToolsVersion="29.0.2" //String defaultMinSdkVersion=22 //Integer - Minimum requirement is Android 5.1 defaultTargetSdkVersion=29 //Integer - We ALWAYS target the latest by default defaultCompileSdkVersion=29 //Integer - We ALWAYS compile with the latest by default }` – user2313833 Jul 15 '21 at 03:33
  • As I said in the answer, workaround may or may not work. You need to wait for cordova 10 version for further updates them. Have you tried `nightly` versions ? – Swaminathan V Jul 15 '21 at 05:35
7

Cordova 11.0.0 is out, but to update this highly ranked question, you have to add the following to your config.xml:

<preference name="android-minSdkVersion" value="19" />
<preference name="android-targetSdkVersion" value="31" />
<preference name="android-compileSdkVersion" value="31" />

Additionally, apps which target Android 12+ have to add

android:exported="true" 

to all Activity and Requirement statements in your manifest -- I had to add this in several places manually to accommodate older plugins.

brianfit
  • 1,829
  • 1
  • 19
  • 34
  • 1
    Why? Can you please add link to docs or explain why these 2 changes are needed? – Paul Verest Mar 31 '23 at 15:28
  • From announce https://cordova.apache.org/announcements/2022/07/12/cordova-android-release-11.0.0.html I would assume values for `android-targetSdkVersion` and `android-compileSdkVersion` should be 32 – Paul Verest Mar 31 '23 at 16:05
  • And could not find anything about `android:exported="true"` – Paul Verest Mar 31 '23 at 16:06
  • 1
    @paulVerest while ago now, but I believe the top answer on this one was my source: https://stackoverflow.com/questions/67412084/android-studio-error-manifest-merger-failed-apps-targeting-android-12/67412314#67412314 – brianfit Apr 22 '23 at 09:10
  • Thanks for link. But for the first part value in 2 lines must be 32: `...SdkVersion" value="32" />` – Paul Verest Apr 24 '23 at 16:17
3

In your config.xml add / update targetSdk version to 30 like below.

<preference name="android-targetSdkVersion" value="30" />

Above command will change targetSdk version to 30

Remove platform android and add back with below command

cordova platform add android@10.0.0

Above command will update compileSdk version to 30. If this step isn't done it will give same value as whatever version was available when you added platform.

Also make sure you have latest sdk and build tool is installed for proper command execution.

nirmal
  • 2,143
  • 1
  • 19
  • 29
  • Is there a way to force cordova-android 10 on packages.json or config.xml? – pauloya Dec 14 '21 at 16:28
  • yes, @pauloya you can define "cordova-android": "10.0.0" in package.json and package-lock.json as well. But still you should run always command cordova platform add android@10.0.0 if it doesn't add/update entry in package.json or lock.json then only do manually – nirmal Dec 15 '21 at 05:46
  • I have an existing Cordova app in the play store using api target level 30. I haven't been able to upgrade to level 31. Question is: how long can my existing app using level 30 able to be discoverable and downloaded by users after november 2022? – A.W. Jun 25 '22 at 09:57
  • 1
    @August They will not take down existing android app unless any security issue is raised. – nirmal Jul 12 '22 at 05:32