You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

为何Android Studio新建API19项目时总是强制安装SDK Platform 26?

Fixing Android Studio Forcing SDK 26 for API 19 Projects

Hey there! Let’s figure out how to fix Android Studio forcing you to download SDK 26 when you’re trying to build an API 19 project. Newer versions of Android Studio default to templates that rely on SDK 26+ (either for AndroidX or newer Support Libraries), but we can tweak the setup to work with your target API 19. Here’s the step-by-step fix:

1. Update Your Module’s build.gradle File

First, open the build.gradle (Module: app) file in your project. This is where the compile/target SDK versions are set. Modify the values to match your API 19 target:

android {
    compileSdkVersion 19  // Change from 26 to 19
    defaultConfig {
        applicationId "com.tomatedigital.myapplication"
        minSdkVersion 19
        targetSdkVersion 19  // Change from 26 to 19
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    // Keep other existing configs like buildTypes, etc.
}

2. Adjust Dependencies to Support API 19

The default dependencies generated for SDK 26 won’t work with API 19—they’ll throw errors because they require a higher compile SDK. You’ll need to swap them for older Support Library versions that support API 19:

  • If your project uses AndroidX (look for androidx.appcompat:appcompat in dependencies), you’ll need to replace those with the old Android Support Library, since AndroidX doesn’t support compile SDK versions below 26.
  • For example, replace this AndroidX dependency:
    implementation 'androidx.appcompat:appcompat:1.3.0'
    
    With this Support Library version (compatible with API 19):
    implementation 'com.android.support:appcompat-v7:21.0.3'
    
  • Remove any other AndroidX-specific dependencies (like androidx.core:core-ktx) since they won’t work with API 19.

3. Disable AndroidX (If Enabled)

If your project automatically enabled AndroidX during creation, you’ll need to turn it off in gradle.properties:

android.useAndroidX=false
android.enableJetifier=false

4. Sync Gradle and Resolve Errors

Click the "Sync Now" button in the top-right corner of Android Studio to apply your changes. If you get any errors, double-check that all dependencies are using versions compatible with API 19—some libraries might require you to use even older versions than the example above.

Quick Tip for Future Projects

If you’re tired of fixing this every time you create a new project, try looking for the "Advanced Options" during project setup (some Android Studio versions hide this, so you might need to expand the menu). If you can set Compile SDK Version to 19 there, it’ll save you the post-creation tweaks. If not, just repeat the steps above—it only takes a minute!

内容的提问来源于stack exchange,提问作者Rafael Lima

火山引擎 最新活动