导航:首页 > 操作系统 > 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源码相关的资料

热点内容
手机文件夹应用推荐怎么关 浏览:605
服务器为什么要分业务口和管理口 浏览:682
杨辉三角java算法 浏览:55
cmd编译错误找不到符号 浏览:695
linuxip机器名 浏览:487
服务器喇叭和频道喇叭有什么区别 浏览:31
闲鱼排名算法如何计算 浏览:975
linuxtargz解压命令 浏览:741
还完房贷后解压手续银行会代办吗 浏览:811
解压烹饪乐高 浏览:675
元神的服务器怎么看 浏览:362
stc8单片机串口中断 浏览:954
信号分析pdf 浏览:927
暴力删除命令 浏览:803
qt如何编译加快速度 浏览:903
php添加数据sql语句 浏览:717
免费的小说app有什么 浏览:405
螺杆压缩机进气阀动画 浏览:651
两台服务器如何做负载均衡 浏览:227
程序员的工资是涨的吗 浏览:813