일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 안드로이드스튜디오opencv
- 안드로이드스튜디오
- 컴활필기두음썜
- AmazonDynamoDB
- DynamoDBExamples
- 개발일지
- GitHub
- 수제비
- git명령어
- 개발
- gitcommit정보확인
- 안드로이드
- AWS
- gitpull
- 컴활필기
- DynamoDBGolang
- OpenCV
- 안드로이드opencv
- golang
- dynamodb
- androidStudio
- androidstudioopencv
- gitcommit정보
- 대학생
- git파일정보확인
- 메모장에있던필기개발일지에옮긴것
- android
- gitpush
Archives
- Today
- Total
주섬주섬 개발일지
Android Studio .so 파일 생성 및 사용하기 본문
.so 파일 Export
Native C++ 디폴트 프로젝트 생성 및 빌드&실행까지 완료한 상태
- Android Studio 메뉴바 Build > Build Bundles(s)
- Build > Build APK(s)
- Analyze APK… → 아래와 같은 app-debug.apk 선택
4. lib 폴더 안에 시스템 별로 .so 파일이 생성되어있는 것을 볼 수 있음
5. 해당 폴더로 이동하여 app-debug.apk를 압축 해제 (반디집 이용)
6.압축 해제 된 app-debug > lib > 하위 폴더들을 복사하여 사용할 수 있음
.so 파일 추가 및 사용
Native C++ 디폴트 프로젝트 생성 완료한 상태
- src>main 폴더에 jniLibs 폴더 생성 후 위의 폴더들을 복사 붙혀넣기
2. CMakeList.txt 라이브러리 추가 및 타겟 설정 (아래는 libmakefile 라이브러리를 추가)
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.18.1)
# Declares and names the project.
project("sofiletest")
add_library(
makefile
SHARED
IMPORTED)
set_target_properties(
makefile
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libmakefile.so)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
sofiletest
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
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)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
sofiletest
makefile
# Links the target library to the log library
# included in the NDK.
${log-lib})
3. MainActivity.java 라이브러리 추가
4. native-lib.cpp 라이브러리 함수 연결하여 사용 가능 (add(), subtract() 함수는 libmakefile의 함수임)
'Programing > Android Studio' 카테고리의 다른 글
Android Studio NDK 지원 OpenCV 라이브러리 사용 방법 (0) | 2024.02.01 |
---|