摇篮:改变NDK构建目标独立于SDK构建目标 [英] Gradle: change NDK build target independent from the SDK build target
问题描述
在我使用的Eclipse项目NDK过去,Android.mk文件是完全适合与API 9级编译NDK,同时让应用程序(SDK)的API级别22.编译,但似乎这是不可能的利用实验摇篮构建系统(2.5)时,与Android 1.3工作室RC1。
我能做些什么只编译NDK的API 9级?
我的典型Android.mk文件看起来是这样的:
APP_PLATFORM:= Android的9
APP_STL:= stlport_static
APP_ABI:= ALL#启用源$ C $ C C ++ 11的一些推广
APP_CPPFLAGS + = -std = C ++ 11在释放模式#Enable optimalization
APP_OPTIM:=释放
我的新gradle这个文件看起来像这样:
应用插件:'com.android.model.application模型{
安卓{
compileSdkVersion = 22
buildToolsVersion =23.0.0 RC3 defaultConfig.with {
的applicationID =com。示例
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 22
版本code = 1
的versionName =1.0
}
} android.ndk {
MODULENAME =NativeLibrary
CPPFLAGS + =-I $ {文件(钢骨混凝土/主/ JNI / some_folder)}的toString()
CPPFLAGS + =-std = C ++ 11 //这里应该加入到编译NDK的API 9? CFLAGS + =-DNDEBUG
CFLAGS + =-fvisibility =隐藏
CPPFLAGS + =-fvisibility =隐藏 LDLIBS + =日志]
STL =stlport_static
} android.buildTypes {
发布 {
isMinifyEnabled =真
proguardFiles + =文件(D:/path/proguard-rules.pro')
}
}
}依赖{
编译文件树(导演:'库',包括:['的* .jar'])
编译com.android.support:support-v4:22.2.0
}
我调查了摇篮来源,它似乎是NDK构建目标是硬codeD一样的compileSdkVersion。有没有避免或改变这种行为的方法?
<一个href=\"https://android.googlesource.com/platform/tools/build/+/c4f572d8dd9664c63a04f48a99b79acfb9513de9/gradle/src/main/groovy/com/android/build/gradle/tasks/NdkCompile.groovy?autodive=0%2F%2F\"相对=nofollow> NdkCompile.groovy (使文件创建)
//目标
IAndroidTarget目标= getPlugin()。loadedSdkParser.target
如果(!target.isPlatform()){
目标= target.parent
}
commands.add(APP_PLATFORM =+ target.hashString())
<一个href=\"https://android.googlesource.com/platform/tools/build/+/c4f572d8dd9664c63a04f48a99b79acfb9513de9/gradle/src/main/groovy/com/android/build/gradle/internal/Sdk.groovy\"相对=nofollow> Sdk.groovy (目标是获取形式compileSdkVersion)
公共SdkParser loadParser(){
checkNotNull(扩展名拓尚未确定) //调用getParser,以确保它的创建。
SdkParser theParser = getParser() 如果(!isSdkParserInitialized){
目标字符串= extension.getCompileSdkVersion()
如果(目标== NULL){
抛出新抛出:IllegalArgumentException(android.compileSdkVersion丢失!)
} FullRevision buildToolsRevision = extension.buildToolsRevision
如果(buildToolsRevision == NULL){
抛出新抛出:IllegalArgumentException(android.buildToolsVersion丢失!)
} theParser.initParser(目标,buildToolsRevision,记录仪) isSdkParserInitialized =真
} 返回theParser
}
如果您使用的是实验性的插件版本0.4。您可以设置
android.ndk {
platformVersion =19
}
In the past I used eclipse for NDK projects, the Android.mk file was perfectly suited for compiling the NDK with API level 9 while letting the app (SDK) compile on API level 22. But it seems that this is not possible when using the experimental Gradle build system (2.5) with Android Studio 1.3 RC1.
What can I do to compile ONLY the NDK on API level 9?
My typical Android.mk file looks like this:
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
My new gradle file looks like this:
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'
}
I investigated the Gradle source and it seems that the NDK build target is hard-coded the same as the compileSdkVersion. Is there an method to avoid or alter this behavior?
NdkCompile.groovy (make file creation)
// target
IAndroidTarget target = getPlugin().loadedSdkParser.target
if (!target.isPlatform()) {
target = target.parent
}
commands.add("APP_PLATFORM=" + target.hashString())
Sdk.groovy (target is fetched form the 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
}
If you are using the experimental plugin version 0.4. you can set
android.ndk {
platformVersion = "19"
}
这篇关于摇篮:改变NDK构建目标独立于SDK构建目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!