Skip to content

Commit

Permalink
Resolve native libraries from AAR file (Maven)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltroger committed Feb 28, 2024
1 parent 2f005b0 commit 733f443
Show file tree
Hide file tree
Showing 362 changed files with 19 additions and 186,358 deletions.
43 changes: 0 additions & 43 deletions .github/workflows/update_opencv.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Copyright of the logo: The Coca-Cola Company
### How do I get set up?
* IDE: Android Studio (tested with 2023.3.1)
* Android SDK & NDK
* Dependencies: OpenCV 4 library (included) [License](/opencv/LICENSE) [Copyright](/opencv/COPYRIGHT)
* Template image location: res/drawable Changeable in CameraPreviewView

### Default template image
Expand Down
56 changes: 13 additions & 43 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,27 @@

#
# Copyright (C) The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

cmake_minimum_required(VERSION 3.4.1)

project(FeatureMatchingNative)
# register the project for the C++ language
project(app CXX)

# create a variable for accessing the opencv library dir
set(
lib_src_dir
${CMAKE_SOURCE_DIR}/../opencv/native
)
# find the opencv native sdk inside the AAR file / maven dependency (prerequisite: prefab = true)
find_package(OpenCV REQUIRED CONFIG)

# register the opencv header files...
include_directories(${lib_src_dir}/jni/include)

# register a new library to import...
# register the custom c++ code of the app
add_library(
lib_opencv
app
SHARED
IMPORTED
src/main/cpp/native_opencv.cpp
)
# ...and assign the corresponding location of the precompiled opencv library
# compile with c++20
set_target_properties(
lib_opencv
PROPERTIES IMPORTED_LOCATION
${lib_src_dir}/libs/${ANDROID_ABI}/libopencv_java4.so
)

# register the custom c++ code of the app as library
add_library(
native_opencv
SHARED
src/main/cpp/native_opencv.cpp
app
PROPERTIES
CXX_STANDARD 20
)

# link the required libs together
target_link_libraries(
native_opencv # includes the custom c++ code of the app
lib_opencv # includes the precompiled opencv lib
android # include android sdk
app # includes the custom c++ code of the app
OpenCV::opencv_java4 # includes the opencv lib from the maven dependency
log # include android logging sdk
)
6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ android {
}
externalNativeBuild {
cmake {
cppFlags += "-std=c++20"
arguments "-DANDROID_STL=c++_shared"
}
}

}
buildTypes {
release {
Expand All @@ -38,6 +39,9 @@ android {
path 'CMakeLists.txt'
}
}
buildFeatures {
prefab true // allows to access native libraries from OpenCV AAR in C++
}
}

kotlin.jvmToolchain(java_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class CameraPreviewView(

// loading C++ libraries
init {
System.loadLibrary("native_opencv")
System.loadLibrary("app")
}
}

Expand Down
11 changes: 0 additions & 11 deletions opencv/COPYRIGHT

This file was deleted.

202 changes: 0 additions & 202 deletions opencv/LICENSE

This file was deleted.

Loading

0 comments on commit 733f443

Please sign in to comment.