I want to change the minimum SDK version in Android Studio from API 12 to API 14. I have tried changing it in the manifest file, i.e.,
For me what worked was: (right click)project->android tools->clear lint markers. Although for some reason the Manifest reverted to the old (lower) minimum API level, but after I changed it back to the new (higher) API level there was no red error underline and the project now uses the new minimum API level.
Edit: Sorry, I see you were using Android Studio, not Eclipse. But I guess there is a similar 'clear lint markers' in Studio somewhere and it might solve the problem.
According to this answer, you just don't include minsdkversion in the manifest.xml, and the build system will use the values from the build.gradle file and put the information into the final apk.
Because the build system needs this information anyway, this makes sense. You should not need to define this values two times.
You just have to sync the project after changing the build.gradle
file, but Android Studio 0.5.2 display a yellow status bar on top of the build.gradle editor window to help you
Also note there at least two build.gradle
files: one master and one for the app/module. The one to change is in the app/module, it already includes a property minSdkVersion
in a newly generated project.
Changing the minSdkVersion in the manifest is not necessary. If you change it in the gradle build file, as seen below, you accomplish what you need to do.
defaultConfig {
applicationId "com.demo.myanswer"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
Gradle Scripts ->
build.gradle (Module: app) ->
minSdkVersion (Your min sdk version)
When you want to update your minSdkVersion in an existent project...
build.gradle(Module: app)
- Make sure is the one under Gradle Script and it is NOT build.gradle(Project: yourproject)
.An example of build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.stackoverflow.answer"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
androidTestCompile 'junit:junit:4.12'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
For beginners in Android Studio "Sync gradle button" is located in Tools -> Android -> Sync Project with Gradle Files "Rebuild project" Build -> Rebuild Project
After updating the build.gradle's minSdkVersion
, you have to click on the button to sync gradle file ("Sync Project with Gradle files"). That will clear the marker.
Updating manifest.xml, for e.g. deleting any references to SDK levels in the manifest file, is NOT necessary anymore in Android Studio.
As now Android Studio is stable, there is an easy way to do it.
PS: Though this question was already answered but Android Studio has changed a little bit by its stable release. So an easy straight forward way will help any new answer seeker landing here.