简体   繁体   English

将Android Studio配置为使用NDK(android-ndk-r10d,Windows 64位)

[英]Configuring Android Studio to use NDK (android-ndk-r10d, Windows 64-bit)

I have an application I'm trying to compile, which uses *.c files. 我正在尝试编译一个使用* .c文件的应用程序。

To compile this I must use NDK. 要进行编译,我必须使用NDK。

Downloaded the 64bit version and browsed the net to find tips on configuring gradle. 下载了64位版本,并在网上浏览了有关配置gradle的技巧。

It seems the config is ok, and gradle attempts to run the NDK build process. 看来配置还可以,并且gradle尝试运行NDK构建过程。

It does this by calling ndk-build.cmd and stops with this error: 它通过调用ndk-build.cmd来完成此操作,并因以下错误而停止:

\\AppData\\Local\\VirtualStore\\Windows\\SysWOW64\\android-ndk-r10d\\ndk-build.cmd": CreateProcess error=2, The system cannot find the file specified \\ AppData \\ Local \\ VirtualStore \\ Windows \\ SysWOW64 \\ android-ndk-r10d \\ ndk-build.cmd“:CreateProcess错误= 2,系统找不到指定的文件

I searched the whole folder for ndk-build.cmd, but there is none. 我在整个文件夹中搜索了ndk-build.cmd,但没有一个。

What in the world am I missing? 我到底想念什么?

EDIT1: The NDK is installed here: EDIT1:NDK安装在这里:

#ndk.dir=C\:\\Users\\user\\AppData\\Local\\VirtualStore\\Windows\\SysWOW64\\android-ndk-r10d

EDIT2: I did try my system path is OK, this is not the problem. EDIT2:我确实尝试过我的系统路径正常,这不是问题。 I did however instal the 32-bit version, and this one does have the *.cmd file. 但是,我确实安装了32位版本,并且该版本确实具有* .cmd文件。

I can now compile the *.c files. 我现在可以编译* .c文件。

I used this command in the AndroidStudio Terminal: 我在AndroidStudio终端中使用了以下命令:

ndk-build -C C:\Users\Thatisme\AndroidStudioProjects\DeezerAP2\app\src\main\jni

All *.c, *.h, *.mk and *.sh were placed in the jni folder as seen in the picture bellow. 如下面的图片所示,所有* .c,*。h,*。mk和* .sh都放置在jni文件夹中。

EDIT3: I can now generate *.so files, but for some reason, the native methods are not found. EDIT3:我现在可以生成* .so文件,但是由于某种原因,找不到本机方法。

EDIT4: 编辑4:

This is how my project looks like: 这是我的项目的样子:

在此处输入图片说明

I manually copied the *.so files in the jniLibs folder. 我手动复制了jniLibs文件夹中的* .so文件。

Is the declaration of the *.c function OK? * .c函数的声明可以吗?

JNIEXPORT jobject JNICALL Java_com_lexample_liggy_ldeezerap_SerialPort_open
  (JNIEnv *env, jclass thiz, jstring path, jint baudrate, jint flags)

EDIT5: I finally did it. EDIT5:我终于做到了。 The correct name of the function is: 该函数的正确名称是:

JNIEXPORT jobject JNICALL Java_com_example_iggy_deezerap_SerialPort_open
  (JNIEnv *env, jclass thiz, jstring path, jint baudrate, jint flags)

Package name is: com.example.iggy.deezerap
Java file calling the function "open()" is: SerialPort
The source file containing the native function is named: SerialPort.c
The function beeing called is: open()

I recompiled the *.c files, copied them also in jniLibs, recompiled the Android project and now it works. 我重新编译了* .c文件,也将它们复制到jniLibs中,重新编译了Android项目,现在它可以工作了。

I'm pretty sure I had this before and I strongly suspect it was due to some sort of mismatch error in the *.c functions. 我很确定我以前有过这个,并且我强烈怀疑这是由于* .c函数中的某种不匹配错误造成的。

About the thing in bold : 关于粗体字的内容

JNIEXPORT jobject JNICALL Java_com_example_iggy_deezerap_ SerialPort _open (JNIEnv *env, jclass thiz, jstring path, jint baudrate, jint flags) JNIEXPORT作业JNICALL Java_com_example_iggy_deezerap_ SerialPort _open(JNIEnv * env,jclass thiz,jstring路径,jint波特率,jint标志)

Does this refer to the *.c file or the *.java file? 这是指* .c文件还是* .java文件?

where is your NDK located ? 您的NDK在哪里? ndk-build.cmd has to be directly inside its directory, else your ndk installation is broken and you have to install/extract it again. ndk-build.cmd必须直接位于其目录内,否则您的ndk安装将被破坏,您必须再次安装/提取它。

Are you setting the path to your NDK correctly. 您是否正确设置了NDK的路径。 Check local.properties file and make sure you have set path to your NDK correctly. 检查local.properties文件,并确保已正确设置NDK的路径。

Check this video for detailed steps on setting up NDK with Android studio https://software.intel.com/en-us/videos/building-ndk-apps-with-android-studio 观看此视频,了解有关使用Android Studio设置NDK的详细步骤https://software.intel.com/zh-cn/videos/building-ndk-apps-with-android-studio

Try using the android NDK_r9d. 尝试使用android NDK_r9d。 In my case i use android NDK_r9d,apache ant 1.9.4,windows 64 bit,and python 2.7.9. 在我的情况下,我使用android NDK_r9d,Apache ant 1.9.4,Windows 64位和python 2.7.9。 Its work perfectly. 它的工作完美。

Full NDK integration with Android Studio is not quite there. NDK与Android Studio的完全集成还不存在。 The NDK is now bundled (sort of) with the Android SDK although it is not downloaded with the SDK. NDK现在已与Android SDK捆绑在一起(某种程度上),尽管未随SDK一起下载。 Once you download Android Studio and the SDK (I believe they are both lumped together in a single download now), open the Android Studio IDE and find the "Project Structure" dialog box and then the "SDK Location" panel. 一旦下载了Android Studio和SDK(我相信它们现在都可以在一个下载中合并在一起),请打开Android Studio IDE,找到“项目结构”对话框,然后找到“ SDK位置”面板。 There you see a download link for the NDK. 在那里,您可以看到NDK的下载链接。 Android Studio downloads the NDK to a folder directly under the Android SDK root in a folder called "ndk-bundle." Android Studio会将NDK下载到Android SDK根目录下直接位于“ ndk-bundle”文件夹中的文件夹中。 Also, you'll want to read up on the Android NDK Preview . 另外,您还需要阅读Android NDK Preview Good luck, it's complicated by the IDE's build system, Gradle and Gradle's different plugin versus Gradle's system versions (blah). 祝您好运,因为IDE的构建系统,Gradle和Gradle的插件与Gradle的系统版本(等等)很复杂。

You can do it in these ways. 您可以通过以下方式进行操作。

a . 一个 add the ANDROID_NDK environgment variable by add export ANDROID_NDK='/Users/roofe/Documents/android-ndk-r14b' to .bash_profile. 通过将export ANDROID_NDK='/Users/roofe/Documents/android-ndk-r14b'到.bash_profile中,添加ANDROID_NDK环境变量。 Then use source ./.bash_profile to load it. 然后使用源./.bash_profile加载它。

b . b add the sdk.dir=/Users/roofe/Library/Android/sdk to local.properties of Android Studio. sdk.dir=/Users/roofe/Library/Android/sdk到Android Studio的local.properties中。

c . c File > Project Structure 文件>项目结构

在此处输入图片说明

download NDK or set the path. 下载NDK或设置路径。

在此处输入图片说明

In case anyone passes by there's a work-around that doesn't involve re-downloading the NDK using Android Studio. 万一有人绕过,有一种解决方法不涉及使用Android Studio重新下载NDK。 As @BoiseBaked points out Android Studio stores the Android NDK in a folder called "ndk-bundle" under the Android SDK's root folder. 正如@BoiseBaked指出的那样,Android Studio将Android NDK存储在Android SDK根文件夹下的“ ndk-bundle”文件夹中。 So, in linux, simply creating a symbolic link (a shortcut, if you use Windows) to the NDK root folder in your SDK root folder solves the problem, like so: 因此,在Linux中,只需在SDK根文件夹中创建指向NDK根文件夹的符号链接(如果使用Windows,则为快捷方式)即可解决该问题,如下所示:

ln -s [FULL_PATH_TO_NDK_ROOT] [FULL_PATH_TO_SDK_ROOT]/ndk-bundle

I believe doing something similar in Windows would work. 我相信在Windows中执行类似的操作也可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用android-ndk-r10d在Windows上编译ffmpeg-2.5.3 - How to compile ffmpeg-2.5.3 on windows with android-ndk-r10d Android Native - 何时使用64位NDK? - Android Native - When to use 64-bit NDK? 您的APP_BUILD_SCRIPT指向一个未知文件:./ jni / Android.mk F:/Android/android-ndk-r10d/build/core/add-application.mk:199: - Your APP_BUILD_SCRIPT points to an unknown file: ./jni/Android.mk F:/Android/android-ndk-r10d/build/core/add-application.mk:199: 哪些版本的Android NDK支持64位体系结构? - Which versions of the Android NDK support 64-bit architectures? 为什么Android NDK对于32位和64位ABI使用不同的GCC版本? - Why does the Android NDK use different GCC versions for 32-bit and 64-bit ABIs? Android NDK r10d错误 - Android NDK r10d error 使用NDK r16b为64位Android构建OpenSSL 1.0.2n对bsd_signal的未定义引用 - Building OpenSSL 1.0.2n for 64-bit Android with NDK r16b undefined reference to bsd_signal 如何使用Windows 7 64位操作系统(Android)使用ndk r12配置FFmpeg库 - How to configure FFmpeg library with ndk r12 using windows 7 64 bit operating system for android 在Windows 64上android ndk r9遗留工具链和android ndk r9有什么区别 - what is the difference between android ndk r9 legacy tool chain and android ndk r9 on windows 64 Android NDK:64位原子(ARM) - android NDK: 64 bit atomics (ARM)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM