Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For android library projects, is <uses-sdk> meaningful in manifest?

Tags:

It's all pretty much in the title. Although I see <uses-sdk> specified in all the example library project's AndroidManifest.xml I've seen, I have a feeling it's irrelevant.

In fact, I suspect that <uses-permission> is also irrelevant, as are all of the attributes of <manifest>, other than package.

Can anyone confirm?

like image 400
Andy Dennie Avatar asked Feb 29 '12 17:02

Andy Dennie


People also ask

What is uses Library in Android manifest?

<uses-library> Note: Google Play uses the <uses-library> elements declared in your app manifest to filter your app from devices that don't meet its library requirements.

What is uses SDK?

An SDK is a toolkit that app developers use to build apps using some prebuilt components instead of having to build each of those components themselves. SDKs are designed to work with specific operating systems, hardware, or computing languages.

Which important attribute of the uses SDK tag Specifies the highest API Level that the Android application supports?

android:maxSdkVersion — Specifies the maximum API Level on which the application is able to run.

What is minimum SDK version?

minSdkVersion is the minimum version of the Android operating system required to run your application. The Android app must have a minimum SDK version 19 or higher. If you want to support devices below API level 19, you must override minSDK version.


2 Answers

As of ADT r20 preview 3

Library manifests can be merged with the main application manifest. This is enabled in an ant build by specifying the property

manifestmerger.enabled=true   

[I'm not sure how to enable it in other (e.g. maven) builds; please comment here if you figure it out. I'm guessing it translates into an aapt command line argument.]

A variety of rules govern conflicts and overriding behavior.

Relative to the specific questions raised here (merging of <uses-sdk> and <uses-permission>), the rules for <uses-sdk> are:

  • minSdkVersion: error if destination manifest contains a value less than the lib value; leave destination value it is same or greater than lib value, store lib value in destination only if none was specified there (defaulting to 1 if not specified in either).
  • targetSdkVersion: warning if destination manifest contains a value less than the lib value; leave destination value it is same or greater than lib value, store lib value in destination only if none was specified there (defaulting to merged minSdkVersion value if not specified in either).

The rule for <uses-permission> is: add library permissions to destination if they are not already present there. It's OK if the same permission is in both.

If you are using ADT r20 preview 2 or earlier, the following applies:

I created a little test library project and a test app that uses it, in order to get to the bottom of this myself. I provided a <uses-sdk> and a <uses-permission> in the library project's manifest, and omitted both of them from the application's manifest.

The result was that the library project's <uses-sdk> and <uses-permission> values were NOT merged into the application at build time, as evidenced by examining the installed app on my device using the AppXplore tool.

My test code is available at https://github.com/adennie/android-library-project-manifest-test.

My conclusion is that specifying <uses-sdk> and <uses-permission> in an Android Library Project's manifest has no effect on the merged manifest of the consuming application.

like image 164
Andy Dennie Avatar answered Oct 22 '22 01:10

Andy Dennie


possible uses of the manifest in library projects:

  1. have you tried lint? it can warn you if your project is using too-new classes/methods which cannot work on the min-sdk that you've set on the manifest. wanna check it out? just press the V-checkbox button near the sdk manager , as shown here: http://tools.android.com/tips/lint/lint-toolbar.png?attredirects=0

  2. the manifest could give a clue for other people of what is required for the project to be used.

  3. you can also add some test activities inside which could allow you to quickly toggle the project from library project to normal project , and do some testing on it.

  4. as google has suggested in the past , library projects might have some use of the manifest in the future by being merged with all of those that use the library project.

in short , the manifest is not meaningless . it can help you a lot .

like image 31
android developer Avatar answered Oct 22 '22 01:10

android developer