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

热点内容
压缩解压王怎么用 浏览:28
服务器共享文件如何备份 浏览:751
买安卓手机怎么在官网买 浏览:119
诗词入门PDF 浏览:358
毒app是什么单位 浏览:61
如何自己编译android系统 浏览:789
phpmysqlpdomysqli 浏览:807
php修改sql语句 浏览:719
android有道api 浏览:386
挠耳营水表用的什么app 浏览:53
战锤40kpdf 浏览:380
java判断字符串是汉字 浏览:467
2017初级教材pdf 浏览:456
松下空调压缩机品牌 浏览:822
python复选框 浏览:751
反诈中心app是什么时候出来的 浏览:591
魔兽世界需要什么服务器地址 浏览:194
啥是单片机休眠 浏览:109
什么音乐app最好 浏览:932
牙膏自制解压神器 浏览:332