Ive been trying for a good bit of time now and can't seem to find a solution to my problem anyhere on here seems like its an error caussed by the Arm64-v8a jni. This is the build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
repositories {
jcenter()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
android {
namespace 'com.example.digitalwhiteboard'
configurations {
extractForNativeBuild
}
compileSdkVersion 33
buildToolsVersion "34.0.0-rc3"
defaultConfig {
applicationId "com.example.digitalwhiteboard"
minSdkVersion 28
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared" ,
"-DANDROID_ARM_NEON=ON",
"-DANDROID_TOOLCHAIN=clang",
"-DANDROID_PLATFORM=android-29",
"-DANDROID_CPP_FEATURES=rtti exceptions",
"-DANDROID_NDK=C:/Users/Kure/AppData/Local/Android/Sdk/ndk/25.2.9519653",
"-DCMAKE_BUILD_TYPE=Release",
"-Wl,--gc-sections"
cFlags "-fstack-protector-all", "-fvisibility=hidden", "-ffunction-sections", "-fdata-sections"
cppFlags "-std=c++17", "-fstack-protector-all", "-fvisibility=hidden", "-ffunction-sections", "-fdata-sections"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
externalNativeBuild {
cmake {
//path file('src/main/cpp/CMakeLists.txt')
path "./CMakeLists.txt"
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
ndkVersion '25.2.9519653'
buildFeatures {
viewBinding true
}
packagingOptions {
//exclude 'lib/arm64-v8a/libpytorch_jni.so'
//exclude 'lib/armeabi-v7a/libnative-lib.so'
//exclude 'lib/x86_64/libnative-lib.so'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
//CameraX
def camerax_version = "1.3.0-alpha04"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:${camerax_version}"
implementation "androidx.camera:camera-extensions:${camerax_version}"
//PyTorch
def pyTorchVersion = "1.12.2"
implementation "org.pytorch:pytorch_android:${pyTorchVersion}"
implementation "org.pytorch:pytorch_android_torchvision:${pyTorchVersion}"
extractForNativeBuild "org.pytorch:pytorch_android:${pyTorchVersion}"
}
task extractAARForNativeBuild {
doLast {
configurations.extractForNativeBuild.files.each {
def file = it.absoluteFile
copy {
from zipTree(file)
into "$buildDir/$file.name"
include "headers/**"
include "jni/**"
}
}
}
}
tasks.whenTaskAdded { task ->
if (task.name.contains('externalNativeBuild')) {
task.dependsOn(extractAARForNativeBuild)
}
}
and this is my Cmake:
cmake_minimum_required(VERSION 3.22.1)
set(TARGET cppNativeFiles)
project(${TARGET} CXX)
set(CMAKE_CXX_STANDARD 17)
set(build_DIR ${CMAKE_SOURCE_DIR}/build)
set(pytorch_testapp_cpp_DIR ${CMAKE_CURRENT_LIST_DIR}/src/main/cpp)
file(GLOB SOURCES
${pytorch_testapp_cpp_DIR}/cppNative.cpp
)
file(GLOB_RECURSE SOURCES src/main/cpp/*.cpp)
add_library(${TARGET} SHARED
src/main/cpp/cppNative.cpp
)
file(GLOB PYTORCH_INCLUDE_DIRS "${build_DIR}/pytorch_android*.aar/headers")
file(GLOB PYTORCH_LINK_DIRS "${build_DIR}/pytorch_android*.aar/jni/${ANDROID_ABI}")
#message(WARNING "<PYTORCH_INCLUDE_DIRS: ${PYTORCH_INCLUDE_DIRS}")
#message(WARNING "<PYTORCH_LINK_DIRS: ${PYTORCH_LINK_DIRS}")
target_compile_options(${TARGET} PRIVATE
-fexceptions
)
set(BUILD_SUBDIR ${ANDROID_ABI})
find_library(PYTORCH_LIBRARY pytorch_jni
PATHS ${PYTORCH_LINK_DIRS}
NO_CMAKE_FIND_ROOT_PATH)
#find_library(FBJNI_LIBRARY fbjni
# PATHS ${PYTORCH_LINK_DIRS}
# NO_CMAKE_FIND_ROOT_PATH)
set(OPENCV_INCLUDE_DIR "${OPENCV_ANDROID_SDK}/sdk/native/jni/include")
target_include_directories(${TARGET} PRIVATE
"${OPENCV_INCLUDE_DIR}"
${PYTORCH_INCLUDE_DIRS})
set(OPENCV_LIB_DIR "${OPENCV_ANDROID_SDK}/sdk/native/libs/${ANDROID_ABI}")
find_library(OPENCV_LIBRARY opencv_java4
PATHS ${OPENCV_LIB_DIR}
NO_CMAKE_FIND_ROOT_PATH)
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)
find_library(jnigraphics-lib jnigraphics)
target_link_libraries(${TARGET}
#myLibary
${PYTORCH_LIBRARY}
#${FBJNI_LIBRARY}
${OPENCV_LIBRARY}
${jnigraphics-lib}
${CMAKE_DL_LIBS}
${log-lib})
Have tried most compile options i could find online to fix the issue. Seems like it's the arm64-v8a used globad symbolsthe other pytorch jni's use as loical and that gives the issue.
I have tried most things i can find online and even tried my luck with Chat-gtp, but still no luck. Im kinda out of ideas and don't know what can solve the issue now. My supervoiser at Uni can't seem to find the issue either.