APP_PLATFORM, android:minSdkVersion 和 android:targetSdkVersion 之间有什么关系? [英] What is the relation between APP_PLATFORM, android:minSdkVersion and android:targetSdkVersion?

查看:41
本文介绍了APP_PLATFORM, android:minSdkVersion 和 android:targetSdkVersion 之间有什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 NDK 功能的 Android 应用.我的应用程序在 jni/Application.mk 中的 AndroidManifest.xmlAPP_PLATFORM 中定义了 android:minSdkVersionandroid:targetSdkVersion.

I'm developing an Android app that uses NDK features. My app defines android:minSdkVersion and android:targetSdkVersion in AndroidManifest.xml and APP_PLATFORM in jni/Application.mk.

我目前的理解是android:minSdkVersion decalres 支持的最低操作系统版本,android:targetSdkVersion 声明要链接的Java 库版本,APP_PLATFORM 声明要链接的 C++ 库.

My current understanding is that android:minSdkVersion decalres minimal supported OS version, android:targetSdkVersion declares Java library version to be linked against, and APP_PLATFORM declares C++ library to be linked against.

两个问题:

  1. 我的理解正确吗?

  1. Is my understanding correct?

APP_PLATFORM 大于 android:minSdkVersion 是否可以?或者它们必须彼此相等?

Is it Ok for APP_PLATFORM to be greater that android:minSdkVersion? Or they must be equal each other?

我的问题的原因:我希望我的应用可用于具有 API >= 10 的设备,但我需要使用 NDK 函数(如 AMotionEvent_getAxisValue)在 NDK 的 platformsandroid-13 文件夹中定义.所以我使用 android:minSdkVersion=10APP_PLATFORM=13.项目编译成功,但能否在 API 10-12 设备上运行?

The reason for my question: I want my app to be available for devices with API >= 10, but I need to use NDK functions (like AMotionEvent_getAxisValue) that are defined in platformsandroid-13 folder in NDK. So I use android:minSdkVersion=10 and APP_PLATFORM=13. Project compiles successfully, but would it be runnable on API 10-12 devices?

推荐答案

  1. android:minSdkVersion 是您的应用所需的最低操作系统版本.

  1. android:minSdkVersion is the minimum OS version that your app expects.

android:targetSdkVersion 本质上是您设计应用程序使用的最大操作系统版本.这是一个如何工作的示例.想象一下,您使用 API 19 很好地测试了您的应用,并且您使用 android:targetSdkVersion=19 发布了您的应用.然后谷歌决定发布 API 20,改变一些 API 的行为,但他们不想改变旧应用程序的行为(以防止破坏它们).因此,当您的应用启动时,Android 看到您的应用具有 targetSdkVersion=19,因此它为您提供旧的 API 行为,但如果其他应用显示 targetSdkVersion=20,Android 将为其提供新的 API 行为.

android:targetSdkVersion is essentially the maximum OS version that you've designed your app to work with. Here's an example of how this works. Imagine that you tested your app fine with API 19 and you release your app with android:targetSdkVersion=19. Then Google decides to release API 20 with a change in behavior of some API, but they don't want to change the behavior for old apps (to prevent from breaking them). So when your app starts up, Android sees that your app has targetSdkVersion=19, so it gives you the old API behavior, but if some other app says targetSdkVersion=20, Android will give it the new API behavior.

APP_PLATFORM 是 NDK 用来编译您的本机代码的本机头文件和库的版本.如果您将 APP_PLATFORM 设置为特定值并且您使用仅在该平台版本中可用的 API,那么您的应用程序将无法在旧平台上正常运行.所以 APP_PLATFORM 是一个最小值.解决方案是使用较低的值而不使用那些较新的 API,或者编写在运行时决定是否调用新 API 的代码(并且可能使用 dlopen/dlsym).

APP_PLATFORM is the version of the native headers and libraries that the NDK will compile your native code with. If you set APP_PLATFORM to a specific value and you use APIs that are only available in that platform version, then your app will not run properly on older platforms. So APP_PLATFORM is a minimum value. The solution is to use a lower value and not use those newer APIs, or to write code that decides at runtime whether to call the new APIs or not (and probably use dlopen/dlsym).

一般来说,使用比 android:minSdkVersion 新的 APP_PLATFORM 值似乎没有意义,除非你正在做一些特殊的事情(比如小心不要通过在运行时检查版本来调用新 API,并确保不要链接到新 API,而是使用 dlopen/dlsym).

It seems like in general it doesn't make sense to use an APP_PLATFORM value newer than android:minSdkVersion, unless you're doing some special (like being careful not to call new APIs by checking the version at runtime, plus making sure not to link to new APIs and instead using dlopen/dlsym).

因此,如果您使用 APP_PLATFORM=13 并调用 AMotionEvent_getAxisValue(这不在早期平台标头中,这意味着它在早期平台上在运行时不可用),您的应用程序将不会在 API << 的设备上运行.13. 一个警告是如果 AMotionEvent_getAxisValue 实际上在旧版本上可用,但它只是不在头文件/库文件中,或者只是没有记录.但我不知道这个特定 API 是否是这种情况(基本上,这需要更多的研究和风险分析,以确定您是否想要依赖不受支持的东西).

So if you use APP_PLATFORM=13 and you call AMotionEvent_getAxisValue (which is not in earlier platform headers, implying that it isn't available at runtime on earlier platforms), your app will not run on devices with API < 13. The one caveat would be if AMotionEvent_getAxisValue is actually available on older versions, but it just wasn't in the header/library files or it just wasn't documented. But I don't know if that's the case for this particular API (basically, that would require more research and risk analysis of whether you want to depend on something unsupported).

这篇关于APP_PLATFORM, android:minSdkVersion 和 android:targetSdkVersion 之间有什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆