일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- git명령어
- androidstudioopencv
- DynamoDBExamples
- gitcommit정보
- androidStudio
- AmazonDynamoDB
- OpenCV
- DynamoDBGolang
- gitcommit정보확인
- 컴활필기
- 안드로이드
- 안드로이드opencv
- GitHub
- gitpush
- git파일정보확인
- 개발일지
- 메모장에있던필기개발일지에옮긴것
- AWS
- android
- 대학생
- dynamodb
- 안드로이드스튜디오
- 개발
- gitpull
- 안드로이드스튜디오opencv
- 수제비
- golang
- 컴활필기두음썜
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 > 하위 폴더들을 복사하여 사용할 수 있음
![](https://blog.kakaocdn.net/dn/3WWr2/btsEbGpKPSr/z2OyKckc2X9i5IZ5NNmQyK/img.png)
.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의 함수임)
![](https://blog.kakaocdn.net/dn/k66GE/btsEdGbMRBO/kci3YNmp4PiWEubDzk8pE1/img.png)
'Programing > Android Studio' 카테고리의 다른 글
Android Studio NDK 지원 OpenCV 라이브러리 사용 방법 (0) | 2024.02.01 |
---|