[Android] Android cross-compile with ndk-build(cpp)
μ΄μ postμ μ΄μ΄μ§λ λ΄μ©μ
λλ€.
ndk-build μ€ν¬λ¦½νΈλ₯Ό μ΄μ©ν cpp μ½λ λΉλ νλ‘μ νΈλ λ°λ‘ μμ΄μ μ 리ν΄λ΄
λλ€.
μ΄μ postμμ ndk-buildλ₯Ό μ΄μ©ν΄μ cμ½λλ₯Ό λΉλνκ³ , android shell μμ μ€νμμΌλ΄€μ΅λλ€.
cppμ½λλ λΉμ·νμ§λ§ μ‘°κΈ λ€λ₯Έ λΆλΆλ μκ³ ,
μ΄ν΄κ° μλλ λΆλΆλ μμ΄ κΈ°λ‘ λ¨κ²¨λ΄
λλ€.
βπ» How to make?
cppμ½λλ₯Ό λΉλνκΈ°μ μμ ν΄λ ꡬμ±μ λ€μκ³Ό κ°μ΄ νμ΅λλ€.
tree . ββ―
.
βββ Android.mk
βββ Application.mk
βββ hello-world.cpp
1 directory, 3 files
ν΄λ ꡬμ±μ κ²½μ°μ μ μ cμ½λ λΉλμ κ°κΈ° λλ¬Έμ μ€λͺ μ μλ΅νκ² μ΅λλ€.
κ°κ°μ νμΌμ λ€μκ³Ό κ°μ΄ μμ±νμμ΅λλ€.
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-world
LOCAL_SRC_FILES := hello-world.cpp
include $(BUILD_EXECUTABLE)
Application.mk
APP_ABI := armeabi-v7a arm64-v8a
APP_PLATFORM := android-23
APP_STL := c++_shared
hello-world.cpp
#include <iostream>
using namespace std;
int main() {
cout << "hello world" << sizeof(char*) << endl;
}
μμ κ°μ΄ μμ±ν΄μ€ νμ jni μμν΄λμμ ndk-build
μ€ν¬λ¦½νΈλ₯Ό μ€νν΄μ£Όλ©΄ λ©λλ€.
μ€ν κ²°κ³Όλ λ€μκ³Ό κ°μ΅λλ€.
$ ndk-build
[armeabi-v7a] Install libs/armeabi-v7a/libc++_shared.so:
[arm64-v8a] Install libs/arm64-v8a/libc++_shared.so:
[armeabi-v7a] Compile++ thumb: hello-world <= hello-world.cpp
[armeabi-v7a] Executable : hello-world
[armeabi-v7a] Install : hello-world => libs/armeabi-v7a/hello-world
[arm64-v8a] Compile++ : hello-world <= hello-world.cpp
[arm64-v8a] Executable : hello-world
[arm64-v8a] Install : hello-world => libs/arm64-v8a/hello-world
μμμ μ μΈνλλ‘ armeabi-v7a
μ arm64-v8a
λ°μ΄λλ¦¬λ§ μμ±ν κ²μ νμΈν μ μμ΅λλ€.
μ€ν
μλλ‘μ΄λ κΈ°κΈ°μμ κ°κ°μ νμΌμ μ€νν κ²°κ³Όμ λλ€.
Leave a comment