41

I would like to see a 'Hello world' program written in C/C++ but made to run on Android.

I know this is possible by using NDK and JNI calls. But not able to make it work. No guides online are helpful.

Need to know to to get started.

I am developing on Windows 7 machine and also using Eclipse for ease.

Android installation path: C:\Program Files\Android\android-sdk-windows and NDK I have extracted to: C:\Program Files\Android\android-ndk-r5

  1. How do I import NDK to eclipse?
  2. How to use C/C++ in Android?

If I could get help running a simple 'hello world' I can design most of my sensitive code with C++.

Cristian
  • 198,401
  • 62
  • 356
  • 264
  • Did you tried the sample projects using the ndk? – Macarse Jan 24 '11 at 02:03
  • @Macarse: yeah! But I just not able to figure out a way to make steps more simpler. Just to get all libraries into eclipse dev environment and make development process even faster. More-over when I follow these steps I cannot get it working. maybe I am Missing so many steps. Each google listing has different opinions/procedures. –  Jan 24 '11 at 02:09
  • 1
    When you always want to get the things done faster and without pain, that's a problem. You must learn first how things work and understand the basis of what you are learning, then you can worry about finding a way to make the development process faster. – Cristian Jan 24 '11 at 02:12

4 Answers4

30

There are samples in the android-ndk-r5 folder + there is a nice step-by-step tutorial:

https://developer.android.com/ndk/samples/index.html

No excuses, dude. You just have to read (take a look at the Exploring the hello-jni Sample section).

Cristian
  • 198,401
  • 62
  • 356
  • 264
  • 9
    "No excuses, dude. You just have to read." You caught me right. Will give a look into. :-) –  Jan 24 '11 at 02:04
4

1) Download NDK from https://developer.android.com/tools/sdk/ndk/index.html.
2) After this copy the location where the ndk is stored.
3) Open preferences from window menu (Eclipse -> Preferences on Mac OS).
4) Inside preferences there is Android title and click that.
5) Then open Ndk and paste the copied Ndk location inside the Edittext.

Now location of the Ndk is set in your eclipse and than

1) create new project.
2) Right click on the project and than select Android Tools and select Add Native.

Support

Automatic creation of jni folder in your project

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
sharma_kunal
  • 2,152
  • 1
  • 28
  • 28
3

Install the SDK and NDK like this: https://askubuntu.com/a/732010/52975

Plug in your device via USB and run:

git clone https://github.com/googlesamples/android-ndk
cd android-ndk
git checkout a5fdebebdb27ea29cb8a96e08e1ed8c796fa52db
cd hello-jni
./gradlew clean
./gradlew assembleDebug
./gradlew installAllDebug

Now the app should be installed in your device.

hello-jni is the simplest C example, and there are also C++ examples like Teapot.

Those examples use Gradle, and there are Ant Android.mk examples under the branch android-mk. You can build those with:

 ndk-build
 android update project -p . -t android-23
 ant clean
 ant debug
 ant installd

Tested on Ubuntu 16.04, Android 5.1.1.

Community
  • 1
  • 1
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
0

1.Creating project and check NDK support.

2.If NDK is not installed ,install it from Android sdk manager.

3.Install Cmack plugin.

4.Synch project

5.Run app

Upgrade Studio version above 2.2