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

热点内容
php对象设置属性 浏览:112
python马赛克 浏览:661
pdf结尾 浏览:126
监控服务器怎么调试 浏览:842
税控盘服务器维护怎么上传 浏览:630
怎么把图片改成线条app 浏览:867
哪个app可以免费看绘画 浏览:152
学心理学可以做程序员吗 浏览:705
最小空调压缩机 浏览:849
金蝶服务器如何修改 浏览:470
单片机原理与接口技术胡汉才 浏览:950
在阿里云服务器如何打开服务器 浏览:310
创建进程的命令 浏览:34
如何加密吃鸡 浏览:724
青春pdf下载 浏览:685
期货交易技术pdf 浏览:645
手机解压加密文件的软件 浏览:895
程序员那么可爱姜妈 浏览:401
vivo手机编译时间为什么晚了 浏览:819
matlab命令行窗口 浏览:708