在 Android Studio 的 build.gradle 中设置 Android R/11 的 API 级别是什么?

Poo*_*ngh 6 android android-11

我可以通过 Android Studio Emulator 使用 API R。我知道我可以直接从 Android Studio 运行,但我仍然想在 Gradle 级别进行设置。

android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
Run Code Online (Sandbox Code Playgroud)

Rya*_*ley 14

现在 Android 11(也称为 Android R)SDK 发布了,编译 SDK 版本很简单30

android {
    compileSdkVersion 30

    defaultConfig {
        targetSdkVersion 30 // Optional: If you want to target R as well
        // ...
    }
    // ... 
}
Run Code Online (Sandbox Code Playgroud)

不再适用:

当Android R处于预览阶段时,编译SDK版本为'android-R',目标SDK版本为'R'

android {
    compileSdkVersion 'android-R'

    defaultConfig {
        targetSdkVersion 'R' // Optional: If you want to target R as well
        // ...
    }
    // ... 
}
Run Code Online (Sandbox Code Playgroud)