Preparation
The android development environment has been configured in the previous chapter. Let's compile and run the hello-JNI example today.
Project path: D: \ android-ndk-r8b \ samples \ hello-JNI
Step 1: import the hello-JNI project to eclipse
Open eclipse and choose File> New> Project> Android project from exsiting code.
Click Next, select the hello-JNI directory in ndk, and click Finish to finish the import.
Now let's take a look at the project file structure. The JNI directory is the c ++ we need to compile.
Deploy hellojni on the android simulator. Right-click the project and choose run as> Android Application. An error occurs during running.
It seems that the cygwin we installed has not been used yet. Now we can use it to compile C ++. Right-click the project, select Properties, open the project properties, and select the builders tab, click new to enable cygwin compiler.
Follow the settings below
Location: D: \ cygwin \ bin \ bash.exe
Working directory: D: \ cygwin \ bin
Arguments: -- login-c "CD/cygdrive/D/android-ndk-r8b/samples/Hello-JNI & ndk-build"
Switch to build options and follow the settings below to clear the compiled so file and generate it again.
Link to the APK file.
Move the ndk_builder to the top
The following figure shows the successful running interface.
Note:
If you have any questions about learning together, please note. For more information, see www.cnblogs.com/dekins.