2

I have a C++ project:

project structer

projectname-
        |
         a_folder ->
                  |- file1.cpp,file2.h
         b_folder ->
                  |- file1.cpp,file2.h
         |
         c_folder ->
                  |
                  c.1_folder->
                             |- file1.cpp,file2.h
                  |
                   file1.cpp,file2.h
         ...
         ...             
         main.cpp
         project_interface.cpp
         project_interface.h

I read a lot on this subject but i don't really understand the flow of the process to make it work.

i manage to get the NDK example work and still after that its not really clear to me.

Also i want to get .a file from the c++ project not import the actually files into my android project. so this example not relevant.

The big question is what is the full process to get c++ project to work in android ?

** The job requirement is android app that use the c++ library to calculate stuff.

**i don't look for the all process to its details just the flow steps.

Maor Hadad
  • 1,850
  • 21
  • 36
  • 1. How do you intend to run the C++ app? 2. You do realize that the .a file is for a specific architecture (CPU type) – Morrison Chang Nov 04 '15 at 15:36
  • Flow steps requires you to understand how you want to call the C++ project. Either you can do it via the command line: http://stackoverflow.com/questions/3350283/any-way-to-run-shell-commands-on-android-programmatically or build a Java NDK API which will call the C++ code. – Morrison Chang Nov 04 '15 at 15:57
  • @morrison With NDK api. – Maor Hadad Nov 04 '15 at 16:36
  • A bit old but may be helpful: http://stackoverflow.com/questions/5659068/jni-tutorial-for-android If you search on 'Java JNI tutorial' the interface is the same on Android as on a PC - its just packaging the binary into the app that is different. – Morrison Chang Nov 04 '15 at 16:48

1 Answers1

0

It sounds like your application is completely c++. The NDK provides a way to compile c++ into your java android app but we can use its compiler to create a cross compiler for android.

1.) Download and install the android SDK and NDK. Install them to a directory within your path.

2.) Compile your c++ using the cross compiler provided with the NDK.

3.) ADB push "binary" "Where ever on the phone you want"

4.) You can run the c++ on the phone

Note: You need a rooted phone to do this kind of development.

In the case that your trying to use the NDK to use the c++ within a native java app. Then the steps are a little different.

1.) Download NDK and SDK

2.) Create android app in java.

3.) Use NDK to build c++ within a project. (There are some nice tutorials for this step)

4.) Call the c++ methods as if they were java methods.

5.) Build the java app normally.

nbroeking
  • 8,360
  • 5
  • 20
  • 40
  • I think you're missing a step like - create Android app to call C++. Unless you are talking about a rooted device. – Morrison Chang Nov 04 '15 at 15:42
  • It looks like the OP isn't trying to add c++ to a android app but instead compile one from scratch. Given the main.cpp. Ill add an edit though just in case. – nbroeking Nov 04 '15 at 15:44
  • The part of the c++ project is to calculate massive data. to preview the data on a device i developing native android app(java). – Maor Hadad Nov 04 '15 at 15:44
  • I'm looking for sections 3 and 4 step. this is the part that not really clear. – Maor Hadad Nov 04 '15 at 16:30
  • Im sorry. One could write a book about the steps for 3 and 4. I know we don't normally post links but I think this tutorial will help you alot. http://www3.ntu.edu.sg/home/ehchua/programming/android/android_ndk.html – nbroeking Nov 05 '15 at 16:00