The version of the project for libraries is higher than the projects using it

I am using an Android library project. I set the goal of creating my library, to say 11, to use api 11 and have advanced compatibility, and I set the check for the min sdk version so that the application does not crash on startup on os <11

My other projects have a build target of 8, so I want to know if this is the right way to set the build version of the library project higher than projects with a lower build goal to use it?

right now I have not seen a single crash. I just want to know if a library with a higher version of the assembly can be used in projects with a lower version of sdk for assembly than the library.

Thanks in advance.:)

+7
source share
4 answers

This is probably possible if the branch checks the SDK version at the code level, for example, if android.os.Build.VERSION.SDK_INT <11 then do not run this, but the dev guide is not recommended:

The platform version must be lower than or equal to the Android project

The library is compiled as part of the dependent application project, so the API used in the library project must be compatible with the version of the Android library used to compile the application project. In general, a library project should use an API level that is the same as or less than the one used by the application. If the library project uses an API level that is higher than that of the application, the application project will not compile. It is quite acceptable to have a library that uses the Android 1.5 API (API level 3) and which is used, for example, in the Android 1.6 project (API level 4) or Android 2.1 (API level 7).

+7
source

You can use a library that supports a higher minSdkVersion than in your project. To do this, add tools:overrideLibrary="<libraries packagename>" manifest-element use-sdk in the project manifest file

<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" tools:overrideLibrary="<libraries packagename>" />

+3
source

Using a library with a higher API level than the application is not recommended. If you specified any API 11 only functions in the library, and then use API 8 to compile with your application, then it should not compile at all. Do you actually have API 11 links in your library code?

See Android docs :

In general, a library project should use an API level that is the same as - or below - that is used by the application. If the library project uses an API level that is higher than the application, the application project will not compile.

+1
source

in your manifest you can simply add:

 <uses-sdk tools:overrideLibrary="<libraries packagename>" /> 
0
source

Source: https://habr.com/ru/post/910460/


All Articles