android - 库项目构建版本高于使用它的项目

标签 android project

我正在使用 Android 库项目。我已将我的库项目构建目标设置为 11 以使用 api 11 并具有向前兼容性,我正在检查最小 sdk 版本,以便应用程序在 os < 11 上运行时不会崩溃

我的其他项目已将构建目标设置为 8,所以我想知道将库项目构建版本设置为高于将使用它的构建目标较低的项目的正确方法吗?

目前我还没有观察到任何崩溃。只是想知道构建版本较高的库是否可以用于构建 sdk 版本低于库的项目。

提前致谢。:)

最佳答案

通过在代码级别分支检查 SDK 版本可能是可行的,例如如果 android.os.Build.VERSION.SDK_INT < 11 则不要运行它,但 dev guide 不推荐这样做:

Platform version must be lower than or equal to the Android project

A 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, the library project should use an API level that is the same as — or lower than — that 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 perfectly acceptable to have a library that uses the Android 1.5 API (API level 3) and that is used in an Android 1.6 (API level 4) or Android 2.1 (API level 7) project, for instance.

关于android - 库项目构建版本高于使用它的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9658188/

相关文章:

android - 在 LG optimus 上使用 RingtoneManager.getRingtone

android - 如何升级到 Android SDK 25.1.3?

Eclipse:完全删除旧项目?

xcode - 获取当前项目在Xcode插件中打开的路径

Java - 测试时隐藏系统输出

短信中的 Android 市场链接

android - 设置 NumberPicker 变量的 setMaxValue 时出现空指针异常

android - 将 ImageView 置于 RelativeLayout 的中间 - Android

java - 如何为新的 java 项目生成 build.xml?

java - 你可以从 Maven 中的父 POM 继承版本吗?