码迷,mamicode.com
首页 > 其他好文 > 详细

NDK 的helloworld步奏

时间:2014-11-05 12:27:46      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   color   ar   java   for   sp   文件   

1. helloworld.c

#include <string.h>

#include <jni.h>





/*

 * Class:     com_example_ndk_NativeHelloworld

 * Method:    hello

 * Signature: ()Ljava/lang/String;

 */

jstring JNICALL Java_com_example_ndk_NativeHelloworld_hello(JNIEnv * env, jclass thiz) {

    return (*env)->NewStringUTF(env, "HelloWorld! I am from JNI !");

}

 

2.Android.mk

LOCAL_PATH := $(call my-dir)  

  

include $(CLEAR_VARS)  

#LOCAL_MODULE

LOCAL_MODULE    := hello  

LOCAL_SRC_FILES := helloworld.c  

  

include $(BUILD_SHARED_LIBRARY) 

3.NativeHelloworld.java

package com.example.ndk;

import android.util.Log;

public class NativeHelloworld {
    public static native String hello();
    
    static {  
        Log.i("NativeClass","before load library");  
        System.loadLibrary("hello");//注意这里为自己指定的.so文件,无lib前缀,亦无后缀  
        Log.i("NativeClass","after load library");    
    }  
}

4.用ndk在项目目录里面编译出hello.so

本人是在linux系统下编译,放到eclipse的libs/armeabi下

5.调用方法,运行

NDK 的helloworld步奏

标签:android   style   blog   color   ar   java   for   sp   文件   

原文地址:http://www.cnblogs.com/superping/p/4075889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!