如何知道我建立了使用NDK的构建的API级别? [英] How to know which API level I'm building for using ndk-build?
问题描述
我想更好地了解使用NDK的构建时API级别的选择如何运作。
I'm trying to better understand how the selection of the api level works when using ndk-build.
我知道我可以明确地设置 APP_PLATFORM
中的 Application.mk 的,而其它NDK的构建将针对在清单与指定的API 安卓的minSdkVersion
,但如果我的应用程序的清单,同时具有安卓的minSdkVersion
和的android: targetSdkVersion
,这比的minSdkVersion高?
I know I can explicitly set APP_PLATFORM
in Application.mk, and that otherwise ndk-build will target the api indicated in the manifest with android:minSdkVersion
, but what if my application's manifest has both android:minSdkVersion
and android:targetSdkVersion
, and this is higher than minSdkVersion?
将NDK的构建目标在 targetSdkVersion ?我怎么能检查?
Will ndk-build target the targetSdkVersion? And how can I check that?
在的情况下,它的目标更高的API层,我想我将能够使用只适用于该级别原生API构建的,但如果我用较低的API级别在设备上运行的应用程序应该惨遭失败,所以在这种情况下,我应该实现某种API级检查的,是正确的?
In case it targets the higher api level, I guess that I will be able to build using native apis only available for that level, but if I run the application on a device with lower api level it should miserably fail, so in that case I should implement some sort of api level checking, is that correct?
推荐答案
将这个code到 Android.mk
刚过定义TARGET_PLATFORM和LOCAL_CFLAGS
Put this code into your Android.mk
just after you define TARGET_PLATFORM and LOCAL_CFLAGS
ifeq ($(TARGET_PLATFORM),android-7)
LOCAL_CFLAGS += -DANDROID7
else
ifeq ($(TARGET_PLATFORM),android-8)
LOCAL_CFLAGS += -DANDROID8
else
ifeq ($(TARGET_PLATFORM),android-9)
LOCAL_CFLAGS += -DANDROID9
endif
endif
endif
现在,你可以检查此定义在C / C ++ code:
Now you can check this defines in your C/C++ code:
#if defined( ANDROID9 )
// do stuff for API Level 9
#endif
这篇关于如何知道我建立了使用NDK的构建的API级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!