導航:首頁 > 操作系統 > 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源碼相關的資料

熱點內容
基於51系列單片機的智能家居 瀏覽:581
看新聞看哪個app 瀏覽:270
android編輯對話框 瀏覽:305
出租天津伺服器雲空間 瀏覽:789
cmd命令結束進程 瀏覽:443
程序員逗比圖片大全 瀏覽:512
免編程游戲引擎 瀏覽:372
微信應用鎖加密 瀏覽:459
數字英雄對程序員的影響 瀏覽:761
程序員培訓學校排名 瀏覽:586
oppo手機如何解開微信的加密 瀏覽:45
學校論文答辯源碼 瀏覽:74
rp在單片機中 瀏覽:186
linux軟體運行命令 瀏覽:354
stcid加密程序 瀏覽:147
把解壓包子放到水裡 瀏覽:294
phpmongodb連接池 瀏覽:953
日本解壓捏泡泡紙 瀏覽:129
環保參比演算法 瀏覽:421
解壓中的刪掉是什麼意思 瀏覽:774