gpt4 book ai didi

android - 如何使用 Gradle 为 Android NDK 指定外部 C++ 源文件夹

转载 作者:太空狗 更新时间:2023-10-29 16:34:50 24 4
gpt4 key购买 nike

我想将一些不在项目树中的 C++ 源文件添加到我的 Android Studio 项目中。我是 Gradle 的新手,并尝试尽可能多地研究它。根据我的阅读,以下 build.gradle 文件应该可以工作,但事实并非如此。关于 jni.sourceDirs 的内容来自这篇文章:http://www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/

这是正确的方法吗?

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.mycompany.myapp"
minSdkVersion 22
targetSdkVersion 22

ndk {
moduleName "mymodule"
ldLibs "log"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

sourceSets.main {
jni.srcDirs '../external/source/dir'
}
}

最佳答案

看看我关于这个的文章: http://www.sureshjoshi.com/mobile/android-ndk-in-android-studio-with-swig/

There are two things you need to know here. By default, if you have external libs that you want loaded into the Android application, they are looked for in the (module)/src/main/jniLibs. You can change this by using setting sourceSets.main.jniLibs.srcDirs in your module’s build.gradle. You’ll need a subdirectory with libraries for each architecture you’re targeting (e.g. x86, arm, mips, arm64-v8a, etc…)

The code you want to be compiled by default by the NDK toolchain will be located in (module)/src/main/jni and similarly to above, you can change it by setting sourceSets.main.jni.srcDirs in your module’s build.gradle

以及来自该页面的示例 Gradle 文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.sureshjoshi.android.ndkexample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"

ndk {
moduleName "SeePlusPlus" // Name of C++ module (i.e. libSeePlusPlus)
cFlags "-std=c++11 -fexceptions" // Add provisions to allow C++11 functionality
stl "gnustl_shared" // Which STL library to use: gnustl or stlport
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

此外,在/jni 目录外部指定时,尝试使用完整构建路径(使用宏之一,例如):

'${project.buildDir}/../../thirdParty/blah/blah/'

关于android - 如何使用 Gradle 为 Android NDK 指定外部 C++ 源文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31303281/

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