Android的工作室,摇篮,OpenCV的和NDK [英] Android Studio, Gradle, OpenCV and NDK

查看:164
本文介绍了Android的工作室,摇篮,OpenCV的和NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试的OpenCV的Andr​​oid,在Android工作室,我感到困惑如何包括NDK。

I am trying to test OpenCV Android, on Android Studio, I am confused about how to include the NDK.

我想要做的就是运行它配备了OpenCV的样本什么。提供的6个样品中,我设法成功运行4。唯一的例外是面部检测和本机的活动。

What I want to do is run the samples which come with OpenCV. Of the 6 samples provided I managed to run 4 successfully. The exceptions were face-detection and native-activity.

我怀疑的原因是我没有设置我的NDK正确。

I suspect the reason is I have not set up my NDK correctly.

谷歌搜索,我发现了一堆的讨论,但并不真正了解他们。这是我第一次我试图同时与NDK和OpenCV,我的摇篮理解的工作是有限的。

Googling I found a bunch of discussions but do not really understand them. This is my first time I am trying to work with both the NDK and OpenCV, and my Gradle understanding is limited.

我在.bash_profile中设置环境变量

I set an environment variable in my .bash_profile

出口ANDROID_NDK = pathTo / Android的NDK-R9

export ANDROID_NDK=pathTo/android-ndk-r9

我不知道如何得到这个工作室。

I do not understand how to get this to studio.

我看参考jniFolder但不明白这是什么意思,我应该关心现在。 <一href="http://stackoverflow.com/questions/20704812/android-studio-0-4-could-not-find-method-jnidir">Stackoverflow.com/questions/17767557

I see reference to jniFolder but do not understand what these are and should I care right now. Stackoverflow.com/questions/17767557

tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'native-libs'))

}

我该怎么做这个贴在我build.gradle文件的末尾?

What am I supposed to do with this paste at the end of my build.gradle file ?

在总结,我的问题是。

  1. 如何让机器人工作室阅读NDK变量?
  2. 到底是什么jniFolders?
  3. 是否足够只是为了我的build.gradle文件的结尾粘贴?

谷歌集团的摇篮和NDK 讨论

对于任何过这个即将到来,这是我怎么解决的,它除了从Xaviers anwser。  首先我读OVERVIEW.html附带了NDK,在docs目录。 然后,我编的.mk和.cpp文件转换为.so文件。我这样做就地样品JNI目录 这造成了我复制到目标所给出的泽维尔libs文件夹的.so文件。

For anyone coming across this this is how I resolved it apart from Xaviers anwser. First I read OVERVIEW.html which comes with the NDK, in the docs directory. I then compiled the .mk and .cpp files into an .so file. I did this inplace in the sample jni directory This created the .so file in the libs folder which I copied to the destination as given by Xavier.

推荐答案

如果您有建立与NDK,并希望把它们放在一个摇篮功能的Andr​​oid项目(使用0.7版本+插件的)库,你可以把它们放在

If you have libraries that you build with the ndk and want to put them in a gradle-enabled android project (using version 0.7.+ of the plugin), you can just put them in

src/main/jniLibs/<abi>/libfoo.so

例如:

src/main/jniLibs/armeabi-v7a/libfoo.so
src/main/jniLibs/x86/libfoo.so

,他们会得到自动打包。

and they'll get packaged automatically.

如果你想保持他们在本机libs文件夹,你可以把你的摇篮文件中的以下内容:

If you want to keep them in the native-libs folder you can put the following in your gradle file:

android {
    sourceSets.main {
        jniLibs.srcDirs = ['native-libs']
    }
}

这一切确确实实是告诉摇篮,其中jniLibs文件夹的主要来源集(相对于项目的根。)

All this does really is tell gradle where the jniLibs folder for the main source set is (relative to the project root.)

您显示的代码段正在做一些不同的东西。它说的是包任务还包括一些本地库。这是一个黑客工具,用来使用不再受支持的任务未公开的API在previous版本工作。

The snippet you showed is doing something different. It's telling the package task to also include some native libraries. This was a hack that used to work in a previous version using undocumented API of the task that are no longer supported.

这篇关于Android的工作室,摇篮,OpenCV的和NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆