Upgrading the 34 API generate apps to not build

Hello team
Google Play Store sent me an email that I need to update my app to API 34 for Google , and the app was not used by me since year now and I changed my PC etc ,
so I have the code now and I changed the API level to 34

    <preference name="android-targetSdkVersion" value="34" />
    <preference name="android-compileSdkVersion" value="34" />
    <preference name="android-buildToolsVersion" value="34.0.0" />

and I have run the following commands :

  • npm install
  • ionic cordova platform add android@10.1.2
  • ionic cordova build android --prod --release
    but the last command failing with this error :
> Task :app:bundleReleaseResources FAILED                                                                                                                                                     
> Task :app:processReleaseResources FAILED

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:bundleReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2ProcessResourcesRunnable
   > AAPT2 aapt2-4.2.2-7147631-windows Daemon #0: Unexpected error during link, attempting to stop daemon.
     This should not happen under normal circumstances, please file an issue if it does.

* 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:
Execution failed for task ':app:processReleaseResources'.
* 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:
Execution failed for task ':app:processReleaseResources'.

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:processReleaseResources'.
* What went wrong:
Execution failed for task ':app:processReleaseResources'.
Execution failed for task ':app:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
   > AAPT2 aapt2-4.2.2-7147631-windows Daemon #1: Unexpected error during link, attempting to stop daemon.
     This should not happen under normal circumstances, please file an issue if it does.

* 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 2s
49 actionable tasks: 3 executed, 46 up-to-date

anyone knows about this issue please ?

here are the project info :

ionic info

Ionic:

   Ionic CLI                     : 6.20.1 (C:\Users\mehdi\AppData\Roaming\nvm\v14.21.1\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.7.5
   @angular-devkit/build-angular : 14.2.13
   @angular-devkit/schematics    : 14.2.13
   @angular/cli                  : 14.2.13
   @ionic/angular-toolkit        : 5.0.3

Cordova:

   Cordova CLI       : 11.1.0
   Cordova Platforms : android 10.1.2
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 22 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : not installed globally

System:

   Android SDK Tools : 26.1.1 (C:\Users\mehdi\AppData\Local\Android\Sdk)
   NodeJS            : v14.21.1 (C:\Program Files\nodejs\node.exe)
   npm               : 8.19.4
   OS                : Windows 10````


npm -v 
6.14.17

node -v 
v14.21.1

gradle -v
Gradle 6.7.1
1 Like

First, you need to be on Cordova 13 in order to support Android SDK 34.

https://cordova.apache.org/docs/en/dev/guide/platforms/android/index.html

but I have another project (app) , in ionic cordova , and it have cordova 11.1.0, and I have succeeded to upgrade to API 34
<preference name="android-targetSdkVersion" value="34" />

ionic info

Ionic:

   Ionic CLI                     : 6.20.1 (C:\Users\mehdi\AppData\Roaming\nvm\v14.21.1\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.0.1
   @angular-devkit/build-angular : 13.0.4

   Ionic CLI                     : 6.20.1 (C:\Users\mehdi\AppData\Roaming\nvm\v14.21.1\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.0.1
   @angular-devkit/build-angular : 13.0.4
   @angular-devkit/schematics    : 13.0.4
   Ionic Framework               : @ionic/angular 6.0.1
   @angular-devkit/build-angular : 13.0.4
   @angular-devkit/schematics    : 13.0.4
   @angular-devkit/build-angular : 13.0.4
   @angular-devkit/schematics    : 13.0.4
   @angular-devkit/schematics    : 13.0.4
   @angular/cli                  : 13.0.4
   @angular/cli                  : 13.0.4
   @ionic/angular-toolkit        : 5.0.3
   @ionic/angular-toolkit        : 5.0.3

Cordova:

   Cordova CLI       : 11.1.0
   Cordova Platforms : android 10.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 7 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : 1.7.0

System:

   Android SDK Tools : 26.1.1 (C:\Users\mehdi\AppData\Local\Android\Sdk)
   NodeJS            : v14.21.1 (C:\Program Files\nodejs\node.exe)
   npm               : 6.14.17
   OS                : Windows 10

I mean, it may work but definitely not officially supported. You are two versions behind on Cordova :grin:

There is this in the error message you posted:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings

As an FYI, Android SDK 34 requires a minimum of AGP 8.1.1 (source) which in turn requires a minimum version of Gradle 8 (source).

Have you tried building it directly in Android Studio? That might give more info. There are also the debug options the error message suggests to get more info.

Try running the following and see what you get (source).

./gradlew build --warning-mode all

how to upgrade Gradle and AGP to these versions correctly ?
when I have tried to install Cordova 13 , it fail always , and when I used latest, it is using cordova 12

Did you manage to resolve the issue? I am facing the same error

yes
basically what I have done :
change:

  • in config.xml :
    <preference name="android-targetSdkVersion" value="34" />
  • npm install
  • ionic cordova build android : this will fail at the end ( my case there was duplicated items in manifest, it is not a big problem, fixed by removing the duplicated inside Android Studio )
  • change the file : cdv-gradle-config.json under platforms/android
{
  "MIN_SDK_VERSION": 22,
  "SDK_VERSION": 34,
  "GRADLE_VERSION": "7.1.1",
  "MIN_BUILD_TOOLS_VERSION": "34.0.0",
  "BUILD_TOOLS_VERSION": "34.0.0",
  "AGP_VERSION": "7.1.2",
  "KOTLIN_VERSION": "1.5.20",
  "ANDROIDX_APP_COMPAT_VERSION": "1.3.0",
  "ANDROIDX_WEBKIT_VERSION": "1.4.0",
  "GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION": "4.3.5",
  "IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED": false,
  "IS_GRADLE_PLUGIN_KOTLIN_ENABLED": false
}

  • Open Android Studio and Open the Project in Android Studio
  • change the build gradle jdk to jdk 11 ( of course it be already installed and configured the needed env variables :
    JAVA_HOME ( system and user ) to JDK11 eg C:\Program Files\Java\jdk-11
add C:\Program Files\Java\jdk-11\bin in PATH ( system and user )
  • then in Android STUDIO , you will hit : Build > Build App Bundle / APK > Build APK
  • normally , Magic will happen and the build will succeed

here are my project info:

node -v 
v14.21.1
npm -v 
6.14.17
cordova -v
11.0.0 (cordova-lib@11.1.0)

ionic info

Ionic:

   Ionic CLI                     : 6.20.1 (C:\Users\mehdi\AppData\Roaming\nvm\v14.21.1\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.7.5
   @angular-devkit/build-angular : 14.2.13
   @angular-devkit/schematics    : 14.2.13
   @angular/cli                  : 14.2.13
   @ionic/angular-toolkit        : 5.0.3

Cordova:

   Cordova CLI       : 11.1.0
   Cordova Platforms : android 10.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 22 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : 1.7.0

System:

   Android SDK Tools : 26.1.1 (C:\Users\mehdi\AppData\Local\Android\Sdk)
   NodeJS            : v14.21.1 (C:\Program Files\nodejs\node.exe)
   npm               : 8.19.4
   OS                : Windows 10