22

I am trying to test my ionic app in android studio. It is throwing the below error.

Gradle sync failed: Cause: compileSdkVersion is not specified.

Any solution for this ? What am I doing wrong.

Here is my build.gradle file

apply plugin: 'com.android.application'

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

// Allow plugins to declare Maven dependencies via build-extras.gradle.

allprojects {
    repositories {
        mavenCentral();
        jcenter()
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.1.0'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:+'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:+'
    implementation 'com.android.support:appcompat-v7:27.+'
}
Amit Anand
  • 687
  • 1
  • 12
  • 25
  • Please give compile sdk version.Like in app level gradle. – debo.stackoverflow May 25 '18 at 14:00
  • 1
    please share your gradle file code – Yogesh Borhade May 25 '18 at 14:01
  • 1
    `compileSdkVersion 25 buildToolsVersion '26.0.2' defaultConfig { applicationId "com.pt.planner" minSdkVersion 21 targetSdkVersion 25 versionCode 24 versionName "2.4.0" multiDexEnabled true` – debo.stackoverflow May 25 '18 at 14:02
  • 1
    compilesdkversion should be same as targetsdkversion – debo.stackoverflow May 25 '18 at 14:02
  • 1
    @Yogesh Borhade - Please check, I have shared the file details – Amit Anand May 25 '18 at 14:11
  • "use this code in your gradle file or check below code " android { // compileSdkVersion 26 buildToolsVersion '27.0.3' defaultConfig { applicationId "com.sportden.proquize" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } – Yogesh Borhade May 25 '18 at 14:14
  • @YogeshBorhade - Could you please confirm to which gradle file I should I add this code. I can see multiple gradle files. 1. build.gradle - under android folder 2. build.gradle - under app folder 3. build.gradle - under cordovaLib folder – Amit Anand May 25 '18 at 14:16
  • 1 st way )instead of Project select android and then find GradleScript -> build.gradle -> (module:app) 2 nd way ) app(folder )-> builde.gradle – Yogesh Borhade May 25 '18 at 14:24

6 Answers6

21

You are using android support library of 27.+ so you will have to give sdk version 27 as compileSdkVersion and targetSdkVersion otherwise your project does not know for which platform your project should be built. These parameter should be given in android directory like this in build.gradle(app):

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.example.abc.test"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Just paste this code below apply plugin: 'com.android.application' this line

Ghulam Moinul Quadir
  • 1,548
  • 1
  • 10
  • 16
  • 1
    Thanks Ghulam Moinul Quadir, it works now. But still the build fails and gives an error 1. cannot find symbol class CallbackContext 2. cannot find symbol class CordovaPlugin 3. cannot find symbol class PluginResult 4. cannot find symbol class CordovaPlugin Please help – Amit Anand May 25 '18 at 14:57
  • @AmitAnand share you `build.gradle(ProjectName)` – Ghulam Moinul Quadir May 25 '18 at 15:14
0

Please Add Below Line in your gradle file

  compileSdkVersion 26

please check below code for reference

android {
        compileSdkVersion 26
        buildToolsVersion '27.0.3'

        defaultConfig {
            applicationId ""
            minSdkVersion 15
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

    }
Yogesh Borhade
  • 665
  • 10
  • 23
0

Note: There was an error in my app/build.gradle, hence it was not reading compileSDKVersion property. When I commented such a line, the error went away:

//def enableHermes = project.ext.react.get("enableHermes", false);

Firstly I got to follow this link:

ReactNative: Building from source

Then this:

ReactNative: android-development-environment

Then you can have this added in your settings.gradle file:

//
include ':ReactAndroid'
//
project(':ReactAndroid').projectDir = new File(
    rootProject.projectDir, '../node_modules/react-native/ReactAndroid')

For my ReactViro Sample project I also had to add dependencies from react-native node_modules directory:

    implementation project(':arcore_client') // remove this if AR not required
    implementation project(':gvr_common')
    implementation project(path: ':viro_renderer')
    implementation project(path: ':react_viro')

and

in my settings.gradle:

//
include ':react_viro', ':arcore_client', ':gvr_common', ':viro_renderer'
project(':arcore_client').projectDir = new File('../node_modules/react-viro/android/arcore_client')
project(':gvr_common').projectDir = new File('../node_modules/react-viro/android/gvr_common')
project(':viro_renderer').projectDir = new File('../node_modules/react-viro/android/viro_renderer')
project(':react_viro').projectDir = new File('../node_modules/react-viro/android/react_viro')
//
Abhinav Saxena
  • 1,940
  • 2
  • 26
  • 54
0

In my case, the error was coming from my own plugin and I fixed it by adding the following line to my plugin.xml file: (which I found simpler than updating the plugin's gradle file)

    <platform name="android">
        <preference name="android-compileSdkVersion" value="30" />
         ...
MIWMIB
  • 1,327
  • 1
  • 13
  • 24
  • It stopped working again. Don't know why cordova is being bit intermittent for me. – MIWMIB Sep 03 '21 at 11:47
  • cordova platform add android was throwing error but build was still running. Updating the plugin's gradle file to `dependencies { implementation "androidx.biometric:biometric:1.1.0" }` filed my issue – MIWMIB Sep 03 '21 at 12:21
0

In my case, I resolved the issue by replacing the old plugin applying syntax:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

with the new plugins DSL in all my build.gradle files:

plugins {
    id "com.android.application"
    id "kotlin-android"
}
Louis CAD
  • 10,125
  • 2
  • 36
  • 56
0

If you are working on a old project and using latest version of Android studio then simply change

compileSdk 27

to

compileSdkVersion 27

on your app level build.gradle file. it will fix this error