5

I need to generate ARM structure shared library for a sampleCPP project.

Sample projects contains:

  • CMakeLists.txt
  • some.cpp (s)
  • Some.h (s)
  • some.tab.cpp.make (S)
  • some.tab.hpp.cmake (s)

Now, I want to create a shared library for a different Android project. I tried to compile with [Android-Cmake][1]but it is generating X86 Architecture library not ARM.

Please let me know if there is another way to do it. Also can i run X86 on Android Platform for all version?

Edit :

Here is my Android.mk:

LOCAL_PATH := $(call my-dir)/../   //Path is according JNI Folder
SRC_TOP_DIR := $(LOCAL_PATH)

include $(CLEAR_VARS)

LOCAL_MODULE := smileParse
LOCAL_CFLAGS := -DANDROID

LOCAL_SRC_FILES := main.cpp test.cpp smamain.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/

1 Answer 1

3

Create a folder called JNI in your project:

enter image description here

Create or Edit Android.mk in JNI folder, set include and library path,

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := some.cpp
include $(BUILD_SHARED_LIBRARY)

Declare a java wrapper class, declare a native function:

public class JWrapperSomeClass {
    public native void Demo(int para);
}

use javah command to generate the function signature for your C++ method wrapper:

javah -jni -classpath bin/classes/ -d jni com.example.Your.Package.Class

Edit the code in C++

Go to your project folder, run command:

$ANDROID_NDK/ndk-build

where $ANDROID_NDK is the folder where you installed android NDK

That is pretty much it. For more details, you might read NDK or JNI documentation.

Sign up to request clarification or add additional context in comments.

5 Comments

David, Please have a look at Edit section in Question. I have added all required .cpp and .h files in Android.mk file. But there are a lot of dependecies written in Cmake.txt. How so i run them? or How should it into Android.mk?
If you have already had cpp files, then add all needed cpp files in Android.mk, then run the ndk-build cmd will do. The cmake is used to generated the needed cpp/header or other files. Do not confuse yourself with cmake and ndk-build. They serve different purposes.
Thanks but one more question, These cpp are written in pure cpp code not in Java JNICPP. Will that affect? Sample of CPP file: github.com/rdkit/rdkit/blob/master/Code/GraphMol/Atom.cpp
These cpp files cannot be directly called in Java. You have to offer java wrapper methods, in which you call cpp functions. Note th native keyword in the answer, it indicated that the function Demo is NOT a pure java function, but implemented in c++! This naming of this c++ function follows specific format, and you'd better have a look at JNI documentation.
How to add multiple .c, .h, .hpp files all together in Android.mk as LOCAL_SRC_FILES? Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.