Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile Cmake file with Android.mk?

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)/
like image 627
Amit Pal Avatar asked Oct 31 '22 21:10

Amit Pal


1 Answers

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.

like image 105
David Avatar answered Nov 11 '22 05:11

David