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
- Open your project in Android Studio and navigate to the
app/src/main/AndroidManifest.xmlfile. - Look for a line that looks like this:
Or if it's combined with other SDK attributes, it might be:<uses-sdk android:minSdkVersion="XX" /><uses-sdk android:minSdkVersion="XX" android:targetSdkVersion="YY" /> - 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
- Now open the
build.gradlefile for your app module (usuallyapp/build.gradleorapp/build.gradle.kts—make sure it's not the project-level one in the root folder). - Find the
defaultConfigblock inside theandroidsection. It should already have some entries likeapplicationId,targetSdkVersion, etc. - Add or update the
minSdkVersionline here. For example:
If you're using Kotlin DSL (android { defaultConfig { applicationId "com.yourpackage.name" minSdkVersion 21 // Replace with your desired minimum SDK version targetSdkVersion 34 versionCode 1 versionName "1.0" } }.ktsfile), 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
相关产品推荐
相关产品推荐

