Reputation: 1575
I am facing this error in android studio 2.2.1 Error:Shared library link file E:\path\3dmodelndk\AssimpAndroid-master\app\src\main\externals\assimp-3.0\libs\armeabi-v7a\libassimp.so does not exist for prebuilt shared library ‘my_assimp:armeabi-v7aDebugShared’
build.gradle:
// Assimp prebuilt shared lib
my_assimp {
// Inform Android Studio where header file dir for this lib
headers.srcDir "src/main/externals/assimp-3.0/include"
// Inform Android Studio where lib is -- each ABI should have a lib file
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("src/main/externals/assimp-3.0/libs/" +
"${targetPlatform.getName()}/libassimp.so")
}
}
buildForAndroid.sh:
//!/bin/sh
//Path to Android NDK
export ANDROID_NDK=$Android_NDK
//Points to the Android SDK
export ANDROID_SDK=$Android_SDK
export PATH=$PATH:$ANDROID_SDK/tools
export PATH=$PATH:$ANDROID_SDK/platform-tools
export PATH=$PATH:$ANDROID_SDK/tools/bin
//from https://github.com/taka-no-me/android-cmake
export ANDROID_STANDALONE_TOOLCHAIN=$ANDROID_SDK/cmake/3.6.3155560 /android.toolchain.cmake
//Add additional args here as appropriate
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_STANDALONE_TOOLCHAIN \
-DANDROID_NDK=$ANDROID_NDK \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_ABI="x86" \
-DANDROID_NATIVE_API_LEVEL=android-9 \
-DANDROID_FORCE_ARM_BUILD=TRUE \
-DCMAKE_INSTALL_PREFIX=install \
..
//This is to remove the versioned shared libs in assimp.
sed -i s/-soname,libassimp.so.3/-soname,libassimp.so/g code/CMakeFiles/assimp.dir/link.txt
//make -j4
Upvotes: 2
Views: 871
Reputation: 65
Am using assimp latest version with AGDK in Android Studio (C++) and the approach i used to generate the .so file was to generate using ninja. Ninja is a small build system with a focus on speed, and it is often used with CMake. You can install it via Ninja's GitHub page or through package managers.
Create a new directory where the build files will be generated. This keeps your source directory clean.
mkdir build
cd build
Now you’ll use CMake to configure the build system for Android. The Android NDK provides a specific CMake toolchain file that you will need to specify. This toolchain helps set the correct environment for Android builds.
cmake -DCMAKE_TOOLCHAIN_FILE=C:\Users\<user>\AppData\Local\Android\Sdk\ndk\<version>\build\cmake\android.toolchain.cmake \
-DANDROID_NDK=C:\Users\<user>\AppData\Local\Android\Sdk\ndk\<version> \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_ABI="armeabi-v7a with NEON" \
-G Ninja \
..
CMAKE_TOOLCHAIN_FILE: This points to the Android NDK CMake toolchain file, which sets up the cross-compilation environment.
ANDROID_NDK: The location of the Android NDK.
CMAKE_BUILD_TYPE: Use Release to build an optimized version of the library.
ANDROID_ABI: Specifies the target architecture for Android. Here, we use armeabi-v7a with NEON.
G Ninja: Use the Ninja build system for fast compilation. Make sure the paths are correct and point to the proper NDK location.
And finally we build the project
cmake --build .
To import the assimp the CMakeList.txt should look something like this
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
cmake_minimum_required(VERSION 3.22.1)
project("project-name")
# Creates your game shared library. The name must be the same as the
# one used for loading in your Kotlin/Java or AndroidManifest.txt files.
add_library(project-name SHARED
main.cpp
)
add_definitions(-DAI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT)
#libassimp
set(ASSIMP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/assimp/include")
set(ASSIMP_LIB_PATH "${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libassimp.so")
include_directories(${ASSIMP_INCLUDE_DIR})
add_library(assimp SHARED IMPORTED)
set_target_properties(assimp
PROPERTIES
IMPORTED_LOCATION ${ASSIMP_LIB_PATH}
INTERFACE_INCLUDE_DIRECTORIES ${ASSIMP_INCLUDE_DIR}
)
# Searches for a package provided by the game activity dependency
find_package(game-activity REQUIRED CONFIG)
# Configure libraries CMake uses to link your target library.
target_link_libraries(project-name
# The game activity
game-activity::game-activity
EGL
GLESv3
jnigraphics
android
log
# Assimp library
assimp)
Note: The Assimp folder must be inside the cpp folder app/src/main/cpp
and you should create a folder called jniLibds inside the directory app/src/main
and modify ur build gradle to add this:
android {
...
sourceSets {
getByName("main") {
jniLibs.srcDirs()
}
}
...
ndk {
abiFilters += listOf("x86_64", "arm64-v8a") // Specify your target ABI
}
}
And inside the jniLibs you should create a folder with the same name as the ABI specified and paste your .so file in there which was build with the ABI specified when building assimp.
Then all left to do is to build the CMakeList.txt in Android Studio and import assimp.
Upvotes: 0