9

We use Microsoft Azure Pipelines for building Ionic apps for both ios and android. Unfortunately we encounter the following error while building the android app.

FAILURE: Build failed with an exception.

* Where:
Build file '/home/vsts/work/1/s/android/capacitor-cordova-android-plugins/build.gradle' line: 21

* What went wrong:
Could not compile build file '/home/vsts/work/1/s/android/capacitor-cordova-android-plugins/build.gradle'.
> startup failed:
  build file '/home/vsts/work/1/s/android/capacitor-cordova-android-plugins/build.gradle': 21: unable to resolve class targetSdkVersion 
   @ line 21, column 26.
             targetSdkVersion targetSdkVersion = project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 29

The strange part is that several days ago it worked without any problems. Commands used to generate the APK

sudo npx jetify

sudo ionic capacitor sync android

cd android && gradle wrapper && sudo ./gradlew assembleRelease `//this is where it fails`

2 Answers 2

30

Strange it is indeed. I have the same issue without any good explanation, but I also have a workable fix. Replacing the line

targetSdkVersion targetSdkVersion = project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 29

with

targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 29

works and it makes some more sense to me than the assignment.

Edit: apparently this is the correct fix, a recent pull request in the capacitor repository does the same: https://github.com/ionic-team/capacitor/pull/4788 or the fixing https://github.com/ionic-team/capacitor/pull/4788/commits/250fdcf03be6510dd629a91a98b5220e14d31664

3
  • 1
    Thanks for the comment! I searched for the text and I found it in the node_modules directory. Don't think that's the right way to replace the line.. or is it?
    – shAkur
    Jul 7, 2021 at 14:56
  • Thx Man ! I resolve my problem with that ! Feb 19, 2022 at 21:12
  • I resolve my problem with that !
    – Hansel
    Apr 3, 2022 at 23:29
0

Ionic App generate some files in folder capacitor-android (if you use capacitor). In this folder, open the manifests/AndroidManisfest.xml and add android:exported="true" where you have without the android:exported. The issue is because Capacitor did not yet add this new requirement in the implementation for Android build script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.