gpt4 book ai didi

android - Gradle:独立于 SDK 构建目标更改 NDK 构建目标

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:15:32 25 4
gpt4 key购买 nike

过去我在 NDK 项目中使用 eclipse,Android.mk 文件非常适合用 API 级别 9 编译 NDK,同时让应用程序 (SDK) 在 API 级别 22 上编译。但似乎这是不可能的当使用带有 Android Studio 1.3 RC1 的实验性 Gradle 构建系统 (2.5) 时。

如何才能在 API 级别 9 上仅编译 NDK?

我的典型 Android.mk 文件如下所示:

APP_PLATFORM := android-9
APP_STL := stlport_static
APP_ABI := all

# Enable c++11 extentions in source code
APP_CPPFLAGS += -std=c++11

#Enable optimalization in release mode
APP_OPTIM := release

我的新 gradle 文件如下所示:

apply plugin: 'com.android.model.application'

model {
android {
compileSdkVersion = 22
buildToolsVersion = "23.0.0 rc3"

defaultConfig.with {
applicationId = "com.example"
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "1.0"
}
}

android.ndk {
moduleName = "NativeLibrary"
cppFlags += "-I${file("src/main/jni/some_folder")}".toString()
cppFlags += "-std=c++11"

//What should be added here to compile the NDK on API 9???

CFlags += "-DNDEBUG"
CFlags += "-fvisibility=hidden"
cppFlags += "-fvisibility=hidden"

ldLibs += ["log"]
stl = "stlport_static"
}

android.buildTypes {
release {
isMinifyEnabled = true
proguardFiles += file('D:/path/proguard-rules.pro')
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.2.0'
}

我调查了 Gradle 源代码,似乎 NDK 构建目标被硬编码为与 compileSdkVersion 相同。有没有办法避免或改变这种行为?

NdkCompile.groovy (创建文件)

// target
IAndroidTarget target = getPlugin().loadedSdkParser.target
if (!target.isPlatform()) {
target = target.parent
}
commands.add("APP_PLATFORM=" + target.hashString())

Sdk.groovy (目标是从 compileSdkVersion 中获取的)

public SdkParser loadParser() {
checkNotNull(extension, "Extension has not been set")

// call getParser to ensure it's created.
SdkParser theParser = getParser()

if (!isSdkParserInitialized) {
String target = extension.getCompileSdkVersion()
if (target == null) {
throw new IllegalArgumentException("android.compileSdkVersion is missing!")
}

FullRevision buildToolsRevision = extension.buildToolsRevision
if (buildToolsRevision == null) {
throw new IllegalArgumentException("android.buildToolsVersion is missing!")
}

theParser.initParser(target, buildToolsRevision, logger)

isSdkParserInitialized = true
}

return theParser
}

最佳答案

如果您使用的是实验性插件版本 0.4。你可以设置

android.ndk {
platformVersion = "19"
}

关于android - Gradle:独立于 SDK 构建目标更改 NDK 构建目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31403772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com