0

Step1: I extracted Android NDK to a directory where SDK is already there. Step2: Created a directory called Project_NDK in it. Step3: I have created the application.mk file and native.c file under jni folder . So where I should put C++ code?

Abhishek Tamta
  • 463
  • 5
  • 14

1 Answers1

1

Typically, you don't place your code under the NDK folder, you place it in the subfolder called "jni" in the Android project. Before you start messing with NDK, you need a regular Android project with a manifest file. You can, in theory, create an NDK-only project without Java, but that's a pain.

In addition to Application.mk you need Android.mk. See the NDK docs for the guidance or look at hello-jni in the samples.

You place your C++ code into files with the .cpp extension, which go into the jni folder as well.

And finally, a word of caution: don't use NDK just because it's tricky and hard to debug. For basic Android programming, just use Java. If you know C++ and you don't know Java, you'll pick it up in an instant, they're close enough.

Chaitanya Bapat
  • 3,381
  • 6
  • 34
  • 59
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • I am working on a project, and for this i am using NDK, i have only study about NDK so please tell me in detail how to do work in NDK, I am using Fedora 14 so please tell me how to install and configure Android-NDK. I had already created the two files application.mk and native.c files under the sub folder "jni", but i don't know in which file i have to put C++ code, and also i can't understand what is the meaning of i need an regular Android project with a manifest. how to create an NDK-project without java. – Abhishek Tamta Apr 02 '13 at 22:49
  • Please read the Android fundamentals document: http://developer.android.com/guide/components/fundamentals.html – Seva Alekseyev Apr 02 '13 at 23:02
  • In the NDK directory, there's a "samples" subdirectory. Under that, there's "native-activity". That's an NDK project without Java. It has a manifest. Study that project, and try doing the same for your project. – Seva Alekseyev Apr 03 '13 at 23:12
  • See this question: http://stackoverflow.com/questions/7899740/android-ndk-tutorial-guide-for-beginners – Seva Alekseyev Apr 04 '13 at 02:18
  • There's no direct analogue to Visual Studio in Linux. Use Eclipse to edit files and build packages. The Android plugin for Eclipse is here: http://developer.android.com/sdk/installing/installing-adt.html – Seva Alekseyev Apr 05 '13 at 00:11
  • I understand your situation. The basic ideas on Linux are all the same as on Windows. You still need Eclipse with Android tools installed. You still need an Android project in Eclipse. You still need a `jni` folder. You still need `Android.mk` in it. Read the guides. Nobody on StackOverflow will give you step-by-step directions, since your question is potentially very big. – Seva Alekseyev Apr 05 '13 at 15:10
  • Rename jni/native.c to native.cpp. Place your C++ code there. If you have more C++ files, place them under `jni` as well. In `Android.mk`, change the LOCAL_SRC value to `native.cpp` instead of `native.c`. Then invoke ndk_build. If you have more .cpp files, put them under `jni` too. – Seva Alekseyev Apr 05 '13 at 19:46
  • I don't want to disclose my e-mail. What is your problem now? – Seva Alekseyev Apr 05 '13 at 20:41
  • Hi Seva, how are you? – Abhishek Tamta Sep 11 '13 at 23:38
  • Hope you will understand my problem and help me because that project Ludo is not completed since February. – Abhishek Tamta Sep 11 '13 at 23:46
  • How will a step by step guide from me differ from a step by step guide by Google or someone else? If you know nothing, educate yourself. The information is out there. I'm not a teacher. Have you read ANY of the links that I've sent you earlier? – Seva Alekseyev Sep 12 '13 at 00:15