Search code examples
androidandroid-11

What is the API level of Android R/11 to set in build.gradle in Android Studio?


I can use API R via Android Studio Emulator. I know I can run directly from Android Studio but still I want to set in Gradle level.

android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

Solution

  • Now that the Android 11 (also known as Android R) SDK is released, the compile SDK version is simply 30:

    android {
        compileSdkVersion 30
    
        defaultConfig {
            targetSdkVersion 30 // Optional: If you want to target R as well
            // ...
        }
        // ... 
    }
    

    No longer applicable:

    When Android R was in the preview stage, the compile SDK version was 'android-R' and the target SDK version was 'R':

    android {
        compileSdkVersion 'android-R'
    
        defaultConfig {
            targetSdkVersion 'R' // Optional: If you want to target R as well
            // ...
        }
        // ... 
    }