[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 λ°”μ΄λ„ˆλ¦¬λ§Œ μƒμ„±ν•œ 것을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

μ‹€ν–‰

μ•ˆλ“œλ‘œμ΄λ“œ κΈ°κΈ°μ—μ„œ 각각의 νŒŒμΌμ„ μ‹€ν–‰ν•œ κ²°κ³Όμž…λ‹ˆλ‹€.

κΉƒν—ˆλΈŒ μ†ŒμŠ€μ½”λ“œ

Categories:

Updated:

Leave a comment