티스토리 뷰
728x90
이전 글에서 만든 정적 라이브러리를 이용해서 안드로이드 ndk 컴파일,
안드로이드에서 실행해보는 것을 정리보았습니다.
testlibjni.h
#include <jni.h> #ifndef _Included_com_example_testlib_TestLib #define _Included_com_example_testlib_TestLib #ifdef __cplusplus extern "C" { #endif JNIEXPORT jstring JNICALL Java_com_example_testlib_TestLib_get_1version(JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif
testlibjni.cpp
#include "testlib.h" #include <jni.h> #include "testlibjni.h" JNIEXPORT jstring JNICALL Java_com_example_testlib_TestLib_get_1version(JNIEnv *env, jobject jobj) { return env->NewStringUTF(get_version()); }
Android.mk
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := testlib LOCAL_SRC_FILES := ../../testlib/src/testlib.cpp LOCAL_C_INCLUDES := \ /cygdrive/c/Android/workspaceCDT/testlib/inc \ $(call include-path-for, graphics corecg) include $(BUILD_STATIC_LIBRARY) # JNI include $(CLEAR_VARS) LOCAL_MODULE := testlibjni LOCAL_SRC_FILES := testlibjni.cpp LOCAL_STATIC_LIBRARIES := testlib LOCAL_C_INCLUDES := \ /cygdrive/c/Android/workspaceCDT/testlib/inc \ $(call include-path-for, graphics corecg) include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL := stlport_static STLPORT_FORCE_REBUILD := true
ndk-build
안드로이드 프로젝트 생성
TestLib.java
package com.example.testlib; public class TestLib { static { System.loadLibrary("testlibjni"); } public native static String get_version(); }
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:padding="@dimen/padding_medium" android:text="@string/hello_world" tools:context=".MainActivity" android:id="@+id/edtTitle" /> </RelativeLayout>
MainActivity.java
package com.example.testlib_android; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.TextView; import com.example.testlib.TestLib; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView edtTitle = (TextView) findViewById(R.id.edtTitle); edtTitle.setText(TestLib.get_version()); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
실행결과
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 송주경
- koba2010
- 튜닝쇼 2008
- Xcode
- 일본여행
- Java
- ble
- MySQL
- 전예희
- Spring MVC
- 레이싱모델 익스트림 포토 페스티벌
- Delphi Tip
- 서울오토살롱
- BPI-M4
- SAS
- flex
- NDK
- ffmpeg
- android
- 지스타2007
- Spring
- ubuntu
- Delphi
- KOBA
- Mac
- 동경
- oracle
- Linux
- sas2009
- JavaScript
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함