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

熱點內容
ubuntu下的python在哪個文件夾 瀏覽:705
app被處罰了怎麼辦 瀏覽:1
plc編譯後錯誤18 瀏覽:612
python數組分片 瀏覽:251
linux圖形化編程 瀏覽:176
阿里國際站app端怎麼裝修 瀏覽:528
微信小程序雲開發簡單搭建源碼 瀏覽:851
以後缺程序員嗎 瀏覽:294
jsp源碼不能運行 瀏覽:364
淘客助手源碼下載 瀏覽:733
如何使用app記賬報稅 瀏覽:562
python線程捕捉鍵盤 瀏覽:25
地推統計圖app怎麼做 瀏覽:162
android文件夾不能用了 瀏覽:857
加密軟體的日誌 瀏覽:893
腎病pdf 瀏覽:231
網站怎麼用本地伺服器 瀏覽:120
javadoc導入android 瀏覽:518
文件掃描成pdf 瀏覽:697
涼山火災救援命令 瀏覽:54