• android开发


    1. java native

    package com.demo;
    
    public class DemoNative {
        public static native void getData(String key);
        
        static{
            System.loadLibrary("demojni");
        }
    }

    2. Android.mk

    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    
    LOCAL_SRC_FILES := com_demo.DemoNamtive.cpp
    
    LOCAL_C_INCLUDES += \
        $(JNI_H_INCLUDE)
    
    LOCAL_SHARED_LIBRARIES := \
        libnativehelper \
        libcutils \
        libutils
    
    LOCAL_MODULE:= libdemojni
    LOCAL_MODULE_TAGS := optional
    LOCAL_PRELINK_MODULE := false
    
    include $(BUILD_SHARED_LIBRARY)    

    3. com_demo.DemoNamtive.cpp

    namespace android {
    
    static void com_demo_DemoNative_getData(JNIEnv* env, jobject obj, jstring data)
    {
        LOGD("get data: %s", data);
    }
    
    static JNINativeMethod gDemoNativeMethods[] =
    {
            {"getData", "(Ljava/lang/String;)V", (void*)com_demo_DemoNative_getData}
    };
    
    
    int register_Native(JNIEnv* env)
    {
          int res = jniRegisterNativeMethods(env, "com/demo/DemoNative",
                  gDemoNativeMethods, NELEM(gDemoNativeMethods));
            LOG_FATAL_IF(res < 0, "Unable to register native methods.");
    
            return 0;
    }
    
    extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
    {
        JNIEnv* env = NULL;
        jint result = -1;
    
        if (vm->GetEnv((void **)&env, JNI_VERSION_1_4)!= JNI_OK)
        {
            LOGE("GetEnv failed!");
            return result;
        }
    
        register_Native(env);
    
        return JNI_VERSION_1_4;
    }
    }  // namespace android

    4. Android.mk

    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    
    LOCAL_MODULE_TAGS := optional
    
    LOCAL_SRC_FILES := $(call all-subdir-java-files)
    
    LOCAL_PACKAGE_NAME := DemoNative
    LOCAL_CERTIFICATE := platform
    
    LOCAL_REQUIRED_MODULES := libdemojni
    LOCAL_JNI_SHARED_LIBRARIES := libdemojni
    include $(BUILD_PACKAGE)
    include $(call all-makefiles-under,$(LOCAL_PATH))

    5. Copy to Androidsrc

    6. mm

    7. adb install out/target/product/generic/system/app/DemoNative.apk

  • 相关阅读:
    ubuntu 10.04安装增强功能 共享文件夹
    CRF简介入门
    Ant 的build.xml 详解
    eclipse中各种颜色和背景的设置
    第13章 类继承 --抽象基类
    第13章 类继承
    团队开发之绩效考核二
    站立会议
    团队站立会议
    团队开发站立会议
  • 原文地址:https://www.cnblogs.com/lavieenrose/p/2585533.html
Copyright © 2020-2023  润新知