导航:首页 > 操作系统 > androidjni源码

androidjni源码

发布时间:2023-09-18 20:09:25

㈠ 如何在android studio中用JNI调用静态库

第一步:我们来看我们的jni目录,目录下包含以下4个文件
Android.mk --- 编译文件
first.c ,first.h --- 外部需要引用的文件
second.c ---- 我们的jni转换文件
首先我们简单的看下源码
#include "first.h"

int first(int x, int y)
{
return x + y;
}
first.c里面简单的定义了一个加法的方法,然后申明了头文件

second.c : 把first.c的方法转换为jni可以识别的方法。
#include "first.h"
#include <jni.h>

jint
java_com_example_twolibs_TwoLibs_add( JNIEnv* env,
jobject this,
jint x,
jint y )
{
return first(x, y);
}

第二步是重点,我们来分析下mk文件,看编译文件是怎样生成first.c对于的静态文件,并在编译second.c的时候加载静态文件
1: LOCAL_PATH:= $(call my-dir)
2:
3: # first lib, which will be built statically
4: #
5: include $(CLEAR_VARS)
6:
7: LOCAL_MODULE := libtwolib-first
8: LOCAL_SRC_FILES := first.c
9:
10: include $(BUILD_STATIC_LIBRARY)
11:
12: # second lib, which will depend on and include the first one
13: #
14: include $(CLEAR_VARS)
15:
16: LOCAL_MODULE := libtwolib-second
17: LOCAL_SRC_FILES := second.c
18:
19: LOCAL_STATIC_LIBRARIES := libtwolib-first
20:
21: include $(BUILD_SHARED_LIBRARY)

如上: 1-10 行是生成静态文件的方法,
14-21 行是编译动态文件的方法,通过标识符BUILD_SHARED_LIBRARY 以及 BUILD_STATIC_LIBRARY 来区分是编译成动态文件还是静态,19行标识需要链接静态库libtwolib-first
第三步:在java中调用
public class TwoLibs extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

TextView tv = new TextView(this);
int x = 1000;
int y = 42;

// here, we dynamically load the library at runtime
// before calling the native method.
//
System.loadLibrary("twolib-second");

int z = add(x, y);

tv.setText( "The sum of " + x + " and " + y + " is " + z );
setContentView(tv);
}

public native int add(int x, int y);
}

你自己理解一下吧

㈡ android 源码dvmusejnibridge在哪

一、下载android 源码 1/android/git-repo/git-repo' 改为清华大学的地址 REPO_URL = 'git://aosp/android/git-repo' 3/platform/manifest 改为清华大学的地址 $ repo init -u git://aosp/android/platform/manifest 4/" /> 改为下面的code即可: <remote name="aosp" fetch="git://aosp/android/" review="https://android-review/" /> 这个方法也可以用来在同步Cyanogenmod代码的时候从TUNA同步部分代码

阅读全文

与androidjni源码相关的资料

热点内容
游戏压缩文件夹怎么删除 浏览:415
百度新闻app是什么 浏览:885
自动化对初级编程的影响 浏览:103
单片机综合课程设计 浏览:598
程序员小严 浏览:811
如何下载欢乐走app 浏览:436
程序员节公司请美女 浏览:14
三本程序员好吗 浏览:20
la78040场幅压缩 浏览:898
MFC经典游戏编程 浏览:784
在线申请小额贷款源码 浏览:331
多个文件夹如何批量删除内容 浏览:249
电力载波单片机 浏览:594
单片机串行通讯 浏览:518
遍历两个对应列表python 浏览:496
数控编程演示软件哪里下载 浏览:691
程序员会6点下班吗 浏览:793
linuxdate时区 浏览:330
小说服务器怎么选 浏览:531
python自动化测试框架哪个最好 浏览:316