I want to change the targetSdkVersion from 19 to 18 in Android Studio (not Eclipse), but failed.
Android Studio complains the following after I changed the targetSdkVersion, and resync the project with Gradle files:
Execution failed for task ':(project name):processDebugManifest'.
> Manifest merging failed. See console for more info.
From the console I found that it is the library I added to the gradle dependencies using the old targetSdkVersion value.
[(Code Directory)\main\AndroidManifest.xml, (Code Directory)\build\exploded-bundles\(Library Directory).aar\AndroidManifest.xml:2] Main manifest has <uses-sdk android:targetSdkVersion='18'> but library uses targetSdkVersion='19'
I learn that in Android Studio, the targetSdkVersion and minSdkVersion flags are defined in the build.gradle file. The project is created with Android Studio's "New project" wizard, and there is NO tag in my code's AndroidManifest.xml. So the problem should not be the two values out of sync. According to the above message, the targetSdkVersion value in the main manifest is what I want.
So the problem should be in the manifest file of the library. I open the library's AndroidManifest.xml file and found the following line:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
Obviously it isn't correct. The problem is that the file is not for manual modification. I tried changing the targetSdkVersion value, and even tried removing the declaration, but it comes back every time I build the project.
I tried cleaning the project, still no luck.
So my question is: Is there a "right" way to alter the targetSdkVersion in Android Studio which I am not aware of?
When you upload an APK, it must meet Google Play's target API level requirements. New apps must target Android 12 (API level 31) or higher; except for Wear OS apps, which must target Android 11 (API level 30) or higher.
Step 1: Open your project in Android mode then go to Gradle Scripts > build. gradle(Module: app) as shown in the following image. Step 2: Refer to the below image and here you have to change the minSdkVersion and targetSdkVersion as per the requirement.
android:targetSdkVersion — Specifies the API Level on which the application is designed to run. In some cases, this allows the application to use manifest elements or behaviors defined in the target API Level, rather than being restricted to using only those defined for the minimum API Level.
Here's how to change the targetSdkVersion
and minSdkVersion
in Android Studio.
Open build.gradle - Path\Your_Application\app\build.gradle
.
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
Change the targetSdkVersion
and minSdkVersion
values to what you desire.
In the Android Studio menu, find "Build" (Alt + b in Windows) and choose "Clean project".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With