1. library 추가시, 아래와 같이 armeabi-v7a로 구성하지 않으면 apk 빌드시 포함되지 않으므로 반드시 추가해 줄 것.
(ndk build시 arch 구분없이 모두 포함하도록 구성하는게 나을듯)
2. 각자 환경에 맞도록 빨간색으로 된 부분을 추가.
app gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "simplendk.android.com.ndksample"
minSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk{
abiFilters 'armeabi-v7a'
}
}
sourceSets {
main{
// let gradle pack the shared library into apk
jniLibs.srcDirs = ['src/main/cpp/libtest']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
3. CMakeLists.txt 수정
cmake_minimum_required(VERSION 3.4.1)
add_library(
native-lib
SHARED
native-lib.cpp )
add_library(test_jni SHARED IMPORTED)
set_target_properties(
test_jni
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/libtest/${ANDROID_ABI}/libtest_jni.so )
#include_directories(${CMAKE_SOURCE_DIR}/libtest/include/)
include_directories(${CMAKE_SOURCE_DIR}/libtest/include/)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries(
native-lib
test_jni
${log-lib} )
하기 링크 참조
https://developer.android.com/studio/projects/add-native-code?hl=ko#create-cmake-script
'android' 카테고리의 다른 글
[NDK] so 포함한 apk가 so loading 실패 (2) (0) | 2018.06.19 |
---|---|
[NDK] so 포함한 apk가 so loading 실패 (0) | 2018.06.18 |
android sdk build tool update 방법 (0) | 2018.06.18 |
platform build with app including gradle. (0) | 2018.06.18 |
apk name 변경하기 (0) | 2018.06.18 |