Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve class targetSdkVersion

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`
like image 464
shAkur Avatar asked Jun 10 '21 13:06

shAkur


People also ask

What is the targetSdkVersion?

android:targetSdkVersion — Specifies the API Level on which the application is designed to run. In some cases, this allows the application to use manifest elements or behaviors defined in the target API Level, rather than being restricted to using only those defined for the minimum API Level.

What is minSdkVersion and targetSdkVersion in Android?

minSdkVersion : The min sdk version is the minimum version of the Android operating system required to run your application. targetSdkVersion : The target sdk version is the version your app is targeted to run on. Follow this answer to receive notifications.


1 Answers

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

like image 52
M-x Avatar answered Sep 24 '22 11:09

M-x