Android Studio的Gradle NDK插件中APP_PLATFORM怎么设置?

人气:377 发布:2022-10-16 标签: android-studio android-ndk gradle-experimental

问题描述

我正在使用 Android Studio 1.5.1 和 Gradle 实验性插件 0.4.0.

I'm building an app with an NDK library using Android Studio 1.5.1 and the Gradle experimental plugin 0.4.0.

即使 Gradle 配置是这样设置的(使用 minSdkVersion.apiLevel = 18),似乎 NDK 库仍然是为 android-21 编译的:

Even though the Gradle config is set as such (with minSdkVersion.apiLevel = 18), it seems like the NDK library is still compiled for android-21:

compileOptions.with {
    sourceCompatibility=JavaVersion.VERSION_1_7
    targetCompatibility=JavaVersion.VERSION_1_7
}

android {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.2"

    defaultConfig.with {
        applicationId = "net.pol_online.hyper"
        minSdkVersion.apiLevel = 18  // Android 4.3 Jelly Bean
        targetSdkVersion.apiLevel = 23  // Android 6.0 Marshmallow
    }
}

是不是因为 APP_PLATFORM 不是由基于最小 SDK 版本的 Gradle NDK 支持自动设置的?如果是这样,你如何解决这个问题?

Is it because APP_PLATFORM is not automatically set by the Gradle NDK support based on the min SDK version? If so how do you fix this?

推荐答案

你可以这样设置:

android.ndk {
   platformVersion = "19"
}

有关详情,请参阅 https://stackoverflow.com/a/33982735/3115956.(实际上,我认为您的库是针对 android-23 构建的,这与针对 android-21 的效果相同 - compileSdkVersion 是影响它的一个(对于 java 和本机代码,除非本机代码被覆盖).

See https://stackoverflow.com/a/33982735/3115956 for details on this. (In practice, I think your library is built targeting android-23, which has the same effect as targeting android-21 - compileSdkVersion is the one that affects it (for both the java and native code, unless the native one is overridden).

984