标签:
public class MainActivity extends Activity { static{ System.loadLibrary("hello"); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View v){ callC(); } public native void callC(); }
Android.mk
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_LDLIBS += -llog LOCAL_MODULE := hello LOCAL_SRC_FILES := hello.c include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_ABI := armeabi x86
#include <jni.h> #include <android/log.h> #define LOG_TAG "System.out" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) void Java_com_itheima_fork_MainActivity_callC(JNIEnv * env, jobject obj){ //分支出c进程 int pid = fork(); //如果为0,分支成功 if(pid == 0){ while(1){ LOGI("hello xiaozhi"); sleep(1); } } }
标签:
原文地址:http://www.cnblogs.com/anni-qianqian/p/5575483.html