0
votes

I have an application I'm trying to compile, which uses *.c files.

To compile this I must use NDK.

Downloaded the 64bit version and browsed the net to find tips on configuring gradle.

It seems the config is ok, and gradle attempts to run the NDK build process.

It does this by calling ndk-build.cmd and stops with this error:

\AppData\Local\VirtualStore\Windows\SysWOW64\android-ndk-r10d\ndk-build.cmd": CreateProcess error=2, The system cannot find the file specified

I searched the whole folder for ndk-build.cmd, but there is none.

What in the world am I missing?

EDIT1: The NDK is installed here:

#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. I did however instal the 32-bit version, and this one does have the *.cmd file.

I can now compile the *.c files.

I used this command in the AndroidStudio Terminal:

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.

EDIT3: I can now generate *.so files, but for some reason, the native methods are not found.

EDIT4:

This is how my project looks like:

enter image description here

I manually copied the *.so files in the jniLibs folder.

Is the declaration of the *.c function OK?

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. 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.

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.

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)

Does this refer to the *.c file or the *.java file?

6
SerialPort specifies the Java class, where your native open(...) function is located.tlau

6 Answers

1
votes

where is your NDK located ? ndk-build.cmd has to be directly inside its directory, else your ndk installation is broken and you have to install/extract it again.

1
votes

Are you setting the path to your NDK correctly. Check local.properties file and make sure you have set path to your NDK correctly.

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

0
votes

Try using the android NDK_r9d. In my case i use android NDK_r9d,apache ant 1.9.4,windows 64 bit,and python 2.7.9. Its work perfectly.

0
votes

Full NDK integration with Android Studio is not quite there. The NDK is now bundled (sort of) with the Android SDK although it is not downloaded with the 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. There you see a download link for the NDK. Android Studio downloads the NDK to a folder directly under the Android SDK root in a folder called "ndk-bundle." Also, you'll want to read up on the 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).

0
votes

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. Then use source ./.bash_profile to load it.

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

c. File > Project Structure

enter image description here

download NDK or set the path.

enter image description here

0
votes

In case anyone passes by there's a work-around that doesn't involve re-downloading the NDK using Android Studio. As @BoiseBaked points out Android Studio stores the Android NDK in a folder called "ndk-bundle" under the Android SDK's root folder. 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:

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

I believe doing something similar in Windows would work.