You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio项目Min SDK配置报错:如何迁移版本至build.gradle?

How to Fix "minSdk version should not be declared in Android Manifest" Issue

No worries, this is a super common tweak since Android Studio now prefers managing SDK versions through Gradle instead of the manifest file. Here's exactly what you need to do:

Step 1: Remove minSdkVersion from your AndroidManifest.xml

  1. Open your project in Android Studio and navigate to the app/src/main/AndroidManifest.xml file.
  2. Look for a line that looks like this:
    <uses-sdk android:minSdkVersion="XX" />
    
    Or if it's combined with other SDK attributes, it might be:
    <uses-sdk android:minSdkVersion="XX" android:targetSdkVersion="YY" />
    
  3. Delete the android:minSdkVersion="XX" part entirely. If the <uses-sdk> tag becomes empty (no attributes left), you can delete the whole tag too—it's not required anymore if you're configuring versions in Gradle.

Step 2: Add minSdkVersion to your Module-level build.gradle

  1. Now open the build.gradle file for your app module (usually app/build.gradle or app/build.gradle.kts—make sure it's not the project-level one in the root folder).
  2. Find the defaultConfig block inside the android section. It should already have some entries like applicationId, targetSdkVersion, etc.
  3. Add or update the minSdkVersion line here. For example:
    android {
        defaultConfig {
            applicationId "com.yourpackage.name"
            minSdkVersion 21 // Replace with your desired minimum SDK version
            targetSdkVersion 34
            versionCode 1
            versionName "1.0"
        }
    }
    
    If you're using Kotlin DSL (.kts file), it'll look like this:
    android {
        defaultConfig {
            applicationId = "com.yourpackage.name"
            minSdk = 21 // Note the syntax is minSdk instead of minSdkVersion
            targetSdk = 34
            versionCode = 1
            versionName = "1.0"
        }
    }
    

Why does this matter?

Android Studio recommends this approach because centralizing SDK version settings in Gradle makes it easier to manage—especially if you have multiple modules in your project. You can even define these versions in a separate gradle.properties file to keep them consistent across all modules.

Once you've made these changes, sync your project with Gradle (click the "Sync Now" prompt that appears in the top right corner) and the error should disappear!

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:12:53