Android Studio: Why Are Minsdkversion and Targetsdkversion Specified Both in Androidmanifest.Xml and Build.Gradle

Android studio: why are minSdkVersion and targetSdkVersion specified both in AndroidManifest.xml and build.gradle?

Gradle overrides the manifest values, and I prefer to update the build.gradle file rather than the manifest. Probably this is the right way using Gradle. Gradle supports product flavours which can be controlled via an IDE and those product flavors can change many things in our Manifest like package name, version code, version name, target SDK and many other. Then by one click in Android Studio you can change many properties and generate another apk.

You can leave the manifest as it is and do all configuration in build.gradle. You can safely remove

<uses-sdk></uses-sdk>

from manifest as well as version codes.

minsdk and targetsdk in Androidmanifest and build.gradle both?

You only need to define the min SDK and target SDK in the build.gradle file. The Gradle build system will automatically define these values in the manifest when you build.

If you define them in both the build.gradle and AndroidManifest.xml files, the settings in the build.gradle file will override the manifest ones.

Best practice is to completely remove the <uses-sdk> tag in the manifest and only use the build.gradle file to specify the min SDK and target SDK. This will not make any difference for older devices; it will run exactly the same.

defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}

The same thing applies for the versionCode and versionName settings.

uses-sdk not present in manifest file

As far as i can tell from google developers tutorials manifest file needs to have it.

Not when you are using Gradle for Android as your build system, such as when you are using Android Studio. The <uses-sdk> information is held in your app's build.gradle file instead. Your app's actual manifest is generated via a manifest merger process that combines the manifest you wrote, manifests from libraries, and Gradle project settings.

how is there no explanation to be found anywhere on the net?

A search on "uses-sdk" "build.gradle" on a major search engine turns up lots of information.

What is the difference between min SDK version/target SDK version vs. compile SDK version?

The min sdk version is the earliest release of the Android SDK that your application can run on. Usually this is because of a problem with the earlier APIs, lacking functionality, or some other behavioural issue.

The target sdk version is the version your application was targeted to run on. Ideally, this is because of some sort of optimal run conditions. If you were to "make your app for version 19", this is where that would be specified. It may run on earlier or later releases, but this is what you were aiming for. This is mostly to indicate how current your application is for use in the marketplace, etc.

The compile sdk version is the version of android your IDE (or other means of compiling I suppose) uses to make your app when you publish a .apk file. This is useful for testing your application as it is a common need to compile your app as you develop it. As this will be the version to compile to an APK, it will naturally be the version of your release. Likewise, it is advisable to have this match your target sdk version.

Android Studio - Can't specify own minSdkVersion

You are using this dependency:

compile "com.android.support:support-v4:+"

In this way you are using the support-v4 in L-preview (21-rc1).

This support lib is declaring minSdkVersion L (you can check the Manifest).

You have to force the minSdkVersion to be 'L' (check the doc: http://developer.android.com/preview/setup-sdk.html)

On the development environment, open the build.gradle file for your module and make sure that:

compileSdkVersion is set to 'android-L'
minSdkVersion is set to 'L'
targetSdkVersion is set to 'L'

It is not a bug, but this is because these APIs are not final. It is a way to prevent installing the apps on a final API 21 device or publishing it on the store using support lib 21-r1.

Manifest merger failed : uses-sdk:minSdkVersion 14

Note: This has been updated to reflect the release of API 21, Lollipop. Be sure to download the latest SDK.

In one of my modules I had the following in build.gradle:

dependencies {
compile 'com.android.support:support-v4:+'
}

Changing this to

dependencies {
// do not use dynamic updating.
compile 'com.android.support:support-v4:21.0.0'
}

fixed the issue.

Make sure you're not doing a general inclusion of com.android.support:support-v4:+ or any other support libraries (v7, v13, appcompat, etc), anywhere in your project.

I'd assume the problem is v4:+ picks up the release candidate (21.0.0-rc1) latest L release which obviously requires the L SDK.

Edit:

If you need to use the new views (CardView, RecyclerView, and Palette), the following should work:

compile "com.android.support:cardview-v7:21.0.0"
compile "com.android.support:recyclerview-v7:21.0.0"
compile "com.android.support:palette-v7:21.0.0"

(Credit to EddieRingle on /androiddev - http://www.reddit.com/r/androiddev/comments/297xli/howto_use_the_v21_support_libs_on_older_versions/)

Another Edit

Be sure to see @murtuza's answer below regarding appcompat-v7 and upvote if it helps!

Android Studio - Can't specify own minSdkVersion

You are using this dependency:

compile "com.android.support:support-v4:+"

In this way you are using the support-v4 in L-preview (21-rc1).

This support lib is declaring minSdkVersion L (you can check the Manifest).

You have to force the minSdkVersion to be 'L' (check the doc: http://developer.android.com/preview/setup-sdk.html)

On the development environment, open the build.gradle file for your module and make sure that:

compileSdkVersion is set to 'android-L'
minSdkVersion is set to 'L'
targetSdkVersion is set to 'L'

It is not a bug, but this is because these APIs are not final. It is a way to prevent installing the apps on a final API 21 device or publishing it on the store using support lib 21-r1.



Related Topics



Leave a reply



Submit