zoukankan      html  css  js  c++  java
  • NDK 的helloworld步奏

    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.调用方法,运行

  • 相关阅读:
    HDU 5744
    HDU 5815
    POJ 1269
    HDU 5742
    HDU 4609
    fzu 1150 Farmer Bill's Problem
    fzu 1002 HangOver
    fzu 1001 Duplicate Pair
    fzu 1150 Farmer Bill's Problem
    fzu 1182 Argus 优先队列
  • 原文地址:https://www.cnblogs.com/superping/p/4075889.html
Copyright © 2011-2022 走看看