compileSdkVersion is not specified. Please add it to build.gradle - Android Studio

I’m new to the ionic world and working with Capacitor, Android Studio etc. I’ve been trying to build an android APK for my project and keep encountering the following error message in Android Studio ‘Cause: compileSdkVersion is not specified. Please add it to build.gradle

I’ve read and tried different suggestions but still haven’t been able to resolve it. My compilleSdkVersion is located in the android/variables.gradle file as indicated in the Capacitor docs, and the configurations seems to be okay. Would appreciate some help on how to resolve the issue? Below are the related configs.:

In android/variables.gradle file

ext {
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
androidxActivityVersion = ‘1.2.0’
androidxAppCompatVersion = ‘1.2.0’
androidxCoordinatorLayoutVersion = ‘1.1.0’
androidxCoreVersion = ‘1.3.2’
androidxFragmentVersion = ‘1.3.0’
junitVersion = ‘4.13.1’
androidxJunitVersion = ‘1.1.2’
androidxEspressoCoreVersion = ‘3.3.0’
cordovaAndroidVersion = ‘7.0.0’
}

In android/app/build.gradle file

apply plugin: ‘com.android.application’

android {
compileSdk compileSdkVersion
defaultConfig {
applicationId “io.myapp.capmpingapp”
minSdkVersion rootProject.ext.minSdkVersion
targetSdk targetSdkVersion
versionCode 1
versionName “1.0”
testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner”
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
// Default: tools/aapt/AaptAssets.cpp - platform/frameworks/base - Git at Google
ignoreAssetsPattern ‘!.svn:!.git:!.ds_store:!.scc:.:!CVS:!thumbs.db:!picasa.ini:!*~’
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
}
}
}

repositories {
flatDir{
dirs ‘…/capacitor-cordova-android-plugins/src/main/libs’, ‘libs’
}
}

dependencies {
implementation fileTree(include: [‘*.jar’], dir: ‘libs’)
implementation “androidx.appcompat:appcompat:$androidxAppCompatVersion”
implementation project(‘:capacitor-android’)
testImplementation “junit:junit:$junitVersion”
androidTestImplementation “androidx.test.ext:junit:$androidxJunitVersion”
androidTestImplementation “androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion”
implementation project(‘:capacitor-cordova-android-plugins’)
}

apply from: ‘capacitor.build.gradle’

try {
def servicesJSON = file(‘google-services.json’)
if (servicesJSON.text) {
apply plugin: ‘com.google.gms.google-services’
}
} catch(Exception e) {
logger.info(“google-services.json not found, google-services plugin not applied. Push Notifications won’t work”)
}

change compileSdk compileSdkVersion to compileSdkVersion rootProject.ext.compileSdkVersion

1 Like

Hey,

I do have exactly how it supposed to be but still getting the same error.

image

image