ndk的入门

news/2024/7/5 1:08:52

第一个ndk

第一步:MainActivity中定义一个方法:

public static native String getStringFromC();

第二步生成头文件:

①我的项目位置:E:\android\HelloNdk

②我的sdk中android.jar包的位置:G:\android\AndroidX86\AndroidX86\sdk\platforms\android-19\android.jar

首先定位到自己项目的位置:

C:\Users\Administrator>cd E:\android\HelloNdk

C:\Users\Administrator>E:

编译头文件:

javah -classpath bin/classes;G:\android\AndroidX86\AndroidX8 6\sdk\platforms\android-19\android.jar -d jni com.example.hellondk.MainActivity

结果:在jni文件夹中生成:comexamplehellondk_MainActivity.h

其中有个方法:

JNIEXPORT jstring JNICALL Javacomexample_hellondkMainActivitygetStringFromC (JNIEnv *, jclass);

写c语言方法和结果

   #include <stdio.h>
    #include <stdlib.h>
    #include "com_example_hellondk_MainActivity.h"
 JNIEXPORT jstring JNICALL Java_com_example_hellondk_MainActivity_getStringFromC
 (JNIEnv * env, jclass jclass)
{
 return (*env)->NewStringUTF(env, "Hello from JNI !");
 }

jni文件夹下面生成Android.mk

可直接复制下载好的ndk中的Android.mk

LOCAL_MODULE := hello//输出的名字

LOCALSRCFILES := hello.c//编译的名字

生成.so文件

定位到项目,然后输入ndk-build

在mainactivity中加载so文件

static {
    System.loadLibrary("hello");
}

注意:生成的so文件的文字是libhello.so文件

Eclipse下配置ndk

Window->Preferences ->Android ->NDK->选择ndk的位置

右击项目->Properties->Builders->New->Program->Location选择ndk的ndk-build.cmd->Working Directory选择Workspace->选择Build Options->勾选During auto builds->点击ok


http://www.niftyadmin.cn/n/3649360.html

相关文章

CentOS 7安装并配置Nginx

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件&#xff08;IMAP/POP3&#xff09;代理服务器&#xff0c;在BSD-like 协议下发行。其特点是占有内存少&#xff0c;并发能力强&#xff0c;事实上nginx的并发能力在同类型的网页服务器中表现较好&#xff0c;中国大陆使…

spring react_如何使用React Spring创建动画的React应用

spring react介绍 (Introduction) Animations add life to your applications and improve the overall user experience. React Spring is an animation package that uses spring-like physics in its core animations to make it easily configurable. Springs are cumulati…

[GOLF]过了磨合期了

今日到了4S店&#xff0c;换了三滤&#xff0c;检查了胎压和空调。换了三滤果然很见效&#xff0c;回去的路上&#xff0c;就觉得爱车凶猛了许多&#xff0c;很给劲儿。第一次开着车去了王府井&#xff0c;并且第一次停到了收费的地下停车场&#xff0c;蜿蜒着下到地下&#xf…

CentOS 7搭建PHP环境

PHP即“超文本预处理器”&#xff0c;是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言&#xff0c;与C语言类似&#xff0c;是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习&#xff0c;使用广泛&#xff0c;主要适用于Web开发领…

Android Context 详解

Android中context可以作很多操作&#xff0c;但是最主要的功能是加载和访问资源。 在android中有两种context&#xff0c;一种是application context&#xff0c;一种是activity context&#xff0c;通常我们在各种类和方法间传递的是activity context。 继承关系&#xff1a;…

如何在JavaScript中替换字符串的所有实例

介绍 (Introduction) Replacing text in strings is a common task in JavaScript. In this article you’ll look at using replace and regular expressions to replace text. 替换字符串中的文本是JavaScript中的常见任务。 在本文中&#xff0c;您将研究如何使用replace和正…

[C#]I/O完成端口的实现

在VC中我几乎每一个Windows Service都是采用I/O完成端口。至于在C#中如何使用I/O完成端口&#xff0c;一直很少见人提及。William Kennedy的三篇文章《IOCP Thread Pooling in C#》&#xff0c;对实现这种机制很有帮助&#xff0c;唯一美中不足的是&#xff0c;它只能把int数值…

MyEclipse 10破解方法及下载地址

破解地址:http://blog.csdn.net/xexiyong/article/details/8273440 下载地址&#xff1a;http://xiazai.sogou.com/detail/34/16/-3776446113025264156.html?e1970