dlopen cannot find .so library at runtime - android

Everything compiled well and my apk is built, but at runtime I get this error:
java.lang.UnsatisfiedLinkError: dlopen failed: library "../../../../libs/x86/mylib.so" not found
I tried to extract the apk and check libs/x86 folder and the .so is there.
My android field at app/build.gradle is:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.example.test"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk {
abiFilters "x86"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

Related

Multiple build variants with cpu architectures in Android Studio

I'm setting up Product Flavor in Android Studio ,there is created multiple build variants in studio
like
FlavourDebug1-armeabi-v7a
FlavourDebug1-arm64-v8a
FlavourDebug1-x86
FlavourDebug1-x86_64
FlavourRelease1-armeabi-v7a
FlavourRelease1-arm64-v8a
FlavourRelease1-x86
FlavourRelease1-x86_64
=============
How to remove that and only get
Debug
Release
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.xxx.smart.xx.launcher"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++14"
}
}
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
javaCompileOptions {
annotationProcessorOptions {
arguments = ['objectbox.debug': 'true']
}
}
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
flavorDimensions "version"
productFlavors {
ChoiceIPTVFlavour {
applicationId 'com.xxx.smart.xx.launcher'
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
PurpleIPTVFlavour {
minSdkVersion 21
applicationId 'com.xxx.smart.xx.launcher'
targetSdkVersion 28
versionCode 1
versionName '1.0'
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
}
remove code like this from your gradle
splits {
abi {
enable true
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include "x86", "x86_64", "armeabi-v7a", "arm64-v8a", "armeabi", "mips", "mips64"
universalApk true //generate an additional APK that contains all the ABIs
}
}

Could not find method path() for arguments

Please someone help me, I'm stuck here.
apply plugin: 'com.android.application'
android{
compileSdkVersion 26
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.glitchrun.sapphire"
minSdkVersion 14
targetSdkVersion 26
externalNativeBuild {
ndkBuild {
path "$projectDir/jni/Android.mk"
}
}
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=$projectDir/jni/Application.mk"
abiFilters "armeabi-v7a", "armeabi", "arm64-v8a", "x86"
cppFlags "-frtti -fexceptions"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
This is my error and I don't know what to do.
Could not find method path() for arguments [C:\Users\costy\AndroidStudioProjects\android\app/jni/Android.mk] on object of type com.android.build.gradle.internal.dsl.ExternalNativeNdkBuildOptions.
I'm trying to export a .apk file and I was stuck with the Deprecated NDK problem. Now I'm stuck with this problem.
The externalNativeBuild block that specifies the makefile path should not be part of defaultConfig, but of its android parent:
android {
compileSdkVersion 26
// etc...
defaultConfig {
applicationId "com.glitchrun.sapphire"
// etc...
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=$projectDir/jni/Application.mk"
abiFilters "armeabi-v7a", "armeabi", "arm64-v8a", "x86"
cppFlags "-frtti -fexceptions"
}
}
}
// etc...
externalNativeBuild {
ndkBuild {
path "$projectDir/jni/Android.mk"
}
}
}
The inner one is used to modify ExternalNativeBuildNdkOptions, while the outer one is used to modify NdkBuildOptions.

External native build issues, build command failed, error while executing 'C:/User/user.../cmake.exe' with arguments {-HF

Recently i have tried to attach cmake with my existing android studio project. I am searching SO since last four day not yet succeeded. Please don't mark this as duplicate. I am running android studio 2.2.1 with gradle version 2.14.1 in windows 8.1pro.
My build.gradle (app level):
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId = "com.example.user.myproject"
minSdkVersion 17
targetSdkVersion 24
multiDexEnabled true
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// proguardFiles.add(file("proguard-rules.txt"))
}
}
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
productFlavors {
arm7 {
// in the future, ndk.abiFilter might also work
ndk {
abiFilter 'armeabi-v7a'
}
}
arm8 {
ndk {
abiFilters 'arm64-v8a'
}
}
arm {
ndk {
abiFilter 'armeabi'
}
}
x86 {
ndk {
abiFilter 'x86'
}
}
x86_64 {
ndk {
abiFilter 'x86_64'
}
}
mips {
ndk {
abiFilters 'mips', 'mips64'
}
}
universal {
ndk {
abiFilters 'mips', 'mips64', 'x86', 'x86_64'
}
}
}
}
dependencies {
My CMakeLists.txt (path: 'app/src/main/cpp')
cmake_minimum_required(VERSION 3.4.1)
add_library(native-lib
SHARED
src/main/cpp/native-lib.cpp)
I am getting this error in message view:
Error while executing 'C:\Users\User\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe' with arguments {-HF:\MyProject\app\src\main\cpp -BF:\MyProject\app\.externalNativeBuild\cmake\x86_64Debug\x86_64 -GAndroid Gradle - Ninja -DANDROID_ABI=x86_64 -DANDROID_NDK=C:\Users\User\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=F:\MyProject\app\build\intermediates\cmake\x86_64\debug\obj\x86_64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:\Users\User\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Users\User\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_TOOLCHAIN=clang}
I don't know what's wrong here.

CMake generates SHARED library but not STATIC library

I am trying to generate a static library using CMAKE and Android Studio(2.3.2). Below is what my CMakeLists.txt looks like. I am unable to generate .a file, however when I change the library to SHARED, CMakeTestModule.so file gets generated when I do "Build->Rebuild Project". Is it required for me to add/set any flag for building STATIC libraries.
cmake_minimum_required(VERSION 3.4.1)
project (CMakeTestProject)
include_directories(
src/main/cpp/
)
add_library(
CMakeTestModule
STATIC
src/main/cpp/CMakeTestModule.cpp
)
add_executable(
CMakeTestModule_test
src/main/cpp/CMakeTestModule_test.cpp
)
target_link_libraries(CMakeTestModule_test CMakeTestModule)
This is what my build.gradle looks like:
apply plugin: 'com.android.library'
android {
compileSdkVersion 16
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
externalNativeBuild {
cmake {
abiFilters 'armeabi'
}
}
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
I fixed this issue by specifying the target in the build.gradle. Something like below. Since apk only uses .so files, we need to mention the targets for static libraries and executables.
apply plugin: 'com.android.library'
android {
compileSdkVersion 16
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
externalNativeBuild {
cmake {
abiFilters 'armeabi'
}
targets "CMakeTestModule_test", "CMakeTestModule"
}
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

How to add cpufeatures to android jni cmake gradle build?

If I have a build.gradle for an application:
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.ndkcmaketest.headwayent.ndkcmaketest"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=gcc"//, "-DANDROID_ALLOW_UNDEFINED_SYMBOLS=TRUE"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
How do I add cpufeatures as ldlibs? Adding ldLibs.addAll(["cpufeatures"]) in externalNativeBuild does not work. And neither adding in an ndk block.
Do you have to add this to build.gradle specifically? If not, add the following to one of your CMakeLists.txt files:
include(AndroidNdkModules)
android_ndk_import_module_cpufeatures()
Then you can target_link_libraries(<your target>, cpufeatures).
That macro and a couple of others are defined in $ANDROID_SDK/cmake/<cmake-version>/share/cmake-<version>/Modules/AndroidNdkModules.cmake.

Categories

Resources