3

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

If you are developing in Eclipse with ADT, use the New Project Wizard to create a new Android project for each sample, using the "Import from Existing Source" option and importing the source from <ndk>/apps/<app_name>/project/. Then, set up an 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 a sample?

Also, can I configure Eclipse to build the C++ portion of the code automatically?

Qwertie
  • 16,354
  • 20
  • 105
  • 148

4 Answers4

5
  1. Click File | New | Project...
  2. Choose Android project, Next
  3. Project Name: This is the project name shown in Package Explorer. It is just a string stored in the .project file that Eclipse creates. No file or folder is created with this name, and the output binaries do not seem to contain this name.
  4. Click "Create project from existing source"
  5. Location: choose the project's root folder, e.g. .../android-ndk-r7b/samples/bitmap-plasma
  6. Click Next and choose your target API. Eclipse does not seem to allow this to be changed later, at least not from the GUI. I don't know why Eclipse does not simply get this information from <uses-sdk> in AndroidManifest.xml or from the "target" line in default.properties. I also don't know why the two may be different (e.g. in the bitmap-plasma sample, target=android-9 but <uses-sdk android:minSdkVersion="8"/>.)
  7. Click next and consider changing the "Package Name" field which defaults to "your.package.namespace". However, the project will run fine if you do not change this field. Leave "Create Activity" and "Create a Test Project" unchecked.
  8. Click Finish. Eclipse will create numerous extra files (e.g. .classpath, .project, project.properties) and folders (bin, gen, assets) alongside the existing code. That's in addition to the output folders created by ndk-build (obj and libs).

Eclipse won't build the native code by itself, but it will automatically deploy the native code (e.g. libplasma.so) if it is aware of it. After you build the native code on the command line, e.g.:

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 choose "Refresh", otherwise Eclipse might fail to upload the native code when it starts the emulator.

Finally, to run the sample, right-click the project and choose Run As | Android application. See here about choosing which emulator is used.

See here about configuring Eclipse to build the native code automatically.

I am curious why NDK produces two *.so files with very different sizes for each ABI, e.g. it creates libs/armeabi-v7a/libplasma.so (15 KB) but also obj/local/armeabi-v7a/libplasma.so (63 KB). Anyone know the difference?

Community
  • 1
  • 1
Qwertie
  • 16,354
  • 20
  • 105
  • 148
1

Instead of going the long winded way ( seasoned programmer love it - but for beginners). There is a way to build the native library in Eclipse and NDK.

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

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

SOURCE

Amit Ahire
  • 303
  • 4
  • 10
0

It seems that with Eclipse Juno, you can now

  1. Click File | New | Project...
  2. Under Android category select Android Project from Existing Code and click Next.
  3. In Root Directory you can then browse and confirm your sample project location.

From here, Eclipse can automatically detect the jni and find the projects.

If this didn't work, go to terminal or command prompt and navigate to your project root directory (where you see jni folder). Then input

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

Here should be, e.g., android-9

After this, try again the initial steps.

kakyo
  • 10,460
  • 14
  • 76
  • 140
0

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

When you import from existing source you have to choose a correct target, I use Android 2.3.3.

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

Finally, only run as android app in Eclipse and it's done

Álvaro
  • 2,872
  • 4
  • 20
  • 25