How do I run the NDK samples?

Sorry to ask a noob question like this, but the NDK documentation is wrong (r7b):

If you are working in Eclipse with ADT, use the New Project wizard to create a new Android project for each sample using the Import from existing source command and import the source from <ndk>/apps/<app_name>/project/

. Then configure the AVD if necessary and build / run the application in the emulator ...

There is no apps folder, and the samples do not contain a project folder. So ... what is the correct way to run the sample?

Also, can I configure Eclipse to automatically build a piece of C ++ code?

+3


source to share


4 answers


  • Click "File" | New | Project...
  • Select Android Project, Next
  • Project Name: This is the name of the project as listed in the Package Explorer. It's just a string stored in the file .project

    that Eclipse creates. No file or folder with this name is created, and the output binaries do not seem to contain this name.
  • Click "Create Project From Existing Source"
  • Location: select the root folder of the project, eg .... / android-ndk-r7b / samples / plasma bitmaps
  • Click Next and select the target API. Eclipse doesn't seem to allow this to be changed later, at least not from the GUI. I don't know why Eclipse doesn't just get this information from <uses-sdk>

    in AndroidManifest.xml or from the default landing page .properties. I also don't know why the two might be different (e.g. in a raster plasma sample target=android-9

    , but <uses-sdk android:minSdkVersion="8"/>

    .)
  • Click Next and consider changing the Package Name field, which defaults to your.package.namespace. However, the project will work fine unless you change this field. Leave Create Event and Create Test Project unchecked.
  • Click Finish. Eclipse will create many additional files (eg .classpath, .project, project.properties) and folders (bin, gen, assets) along with the existing code. This is in addition to the output folders generated by ndk-build (obj and libs).

Eclipse will not write native code itself, but it will automatically deploy native code (like libplasma.so) if it knows about it. After you build your own code on the command line like:

C:\...\android-ndk-r7b\samples\bitmap-plasma>..\..\ndk-build
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
"Compile thumb : plasma <= plasma.c
SharedLibrary  : libplasma.so
Install        : libplasma.so => libs/armeabi/libplasma.so
"Compile thumb : plasma <= plasma.c
SharedLibrary  : libplasma.so
Install        : libplasma.so => libs/armeabi-v7a/libplasma.so

      

Right-click your project and select Refresh, otherwise Eclipse might not load native code when the emulator starts.



Finally, to run the sample, right-click on the project and select Run As | Android App. See here for information on choosing which emulator to use.

See here about setting up Eclipse to generate native code automatically.

I'm curious why the NDK creates two * .so files with very different sizes for each ABI, for example. it creates libs/armeabi-v7a/libplasma.so

(15KB) but also obj/local/armeabi-v7a/libplasma.so

(63KB). Does anyone know the difference?

+5


source


Instead of going in a long, winding way (experienced programmer loves it - but for beginners). There is a way to create a native library in Eclipse and NDK.

1> First you need to make sure the NDK path is correct in Windows -> Preferences -> (tabs) Android -> NDK - if not set - point it to the ndk directory.



2> Assuming you imported the project as described above (New | Project | Create from Existing Code). You right click on the project and go to "Android Tools -> Add Root Support ..". If the path is set, it will build an example. And then you can deploy it to device or AVM by clicking play button.

SOURCE

+1


source


I am working with Eclipse ADT and Android ndk 5b. My correct project path is android-ndk-5b / samples / project

When importing from an existing source you have to select the correct target, I am using Android 2.3.3.

After that I updated my project from command line, take a look at this link, http://developer.android.com/sdk/ndk/overview.html From the example path write: android update project -p. -s and $ Your_Path_Android_ndk / ndk-build

Finally, only runs as an Android app in Eclipse and this is done

0


source


It seems that with Eclipse Juno now you can

  • Click "File" | New | Project...
  • Under the Android category, select Android Project from Existing Code and click Next.
  • In the root directory, you can view and confirm your approximate project location.

This is where Eclipse can automatically detect jni and find projects.

If that didn't work, go to terminal or command line and navigate to your project root (where you can see the jni folder). Then enter

android update project -p . -t <your target level>

      

There should be for example android-9

Then repeat the initial steps.

0


source







All Articles