1

I wish to include yctung's AndroidLibSVM into my project, so i followed his instructions to import the .AAR and set the dependencies.

Install

Install is easy, you just import our AAR library into your Android project >by the following steps:

Right-click your module -> new -> module -> Import .JAR/.AAR Package -> >select our Release/androidlibsvm-release.aar

After this, you should add the app dependency by:

Right-click your app module -> open module setting -> clieck your app -> >dependencies -> + -> module dependency -> androidlibsvm

Now I could import and work with his library as expected and Android Studio would compile the code and build without any errors. The app runs fine on an emulated device, however, it crashes on my physical device as soon as it tries to run the part of code referring to yctung's library with the following error:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__aeabi_memcpy" referenced by "/data/app/com.krautkremer.nils.mymirror-1/lib/arm/libjnilibsvm.so"

Referring to this SO-question, the error might be caused by incorrect Cmake/Gradle settings. If I get it right, Tung used ndk-build for his project, while I am building with Cmake. Therefor, his instructions on how to install his library may not be sufficient in my case. In fact, i haven't made any changes to the default CMakeLists.txt which i unterstand to be crucial for Cmake. I tried to add a few lines in the build.gradle and/or the CmakeLists file as they are commonly suggested in SO-solutions with no success, but i have to admit, i really don't understand what i am doing, even after reading the official guide. I am kind of lost here, since i hardly know the difference between ndk-build and Cmake, not to mention how to set them up correctly or if this is even necessary in this case. I'd be most grateful if someone could explain to me, how i can integrate AndroidLibSVM into my project correctly, what changes i have to make to my gradle/cmake files and how i have to set up my directories (in case this is part of the answer). All i've downloaded so far is the .aar which indeed does contain a few .so files but i don't understand where to put them.

Now, this is my build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 28


defaultConfig {
    applicationId "com.krautkremer.nils.mymirror"
    minSdkVersion 23
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    externalNativeBuild {
        cmake {
            cppFlags ""
            arguments "-DANDROID_PLATFORM=android-23"
        }
    }

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    //exclude 'META-INF/proguard/androidx-annotations.pro'
}

externalNativeBuild {
    cmake {
        path "CMakeLists.txt"


    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.media:media:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation 'androidx.annotation:annotation:1.0.1'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-ml-vision:18.0.2'
implementation 'com.google.firebase:firebase-ml-common:16.1.6'
implementation 'com.google.firebase:firebase-ml-vision-face-model:17.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1-alpha01'
implementation project(':androidlibsvm-release')
}
apply plugin: 'com.google.gms.google-services'

and this is my CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)


add_library( 
    native-lib

    SHARED

    src/main/cpp/native-lib.cpp)


find_library( 
    log-lib
    log)

target_link_libraries( 
    native-lib

    ${log-lib})

This is my directory structure.

Thank you in advance. If you need more to help me, i'd be happy to help you help me;)

Community
  • 1
  • 1
Nils Krautkremer
  • 123
  • 3
  • 14
  • This looks a lot like https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#cannot-locate-symbols, but if I'm reading everything here correctly the minSdkVersion is 23, not 24, which I thought wouldn't have that problem. What device are you running this on? What OS version does it have? – Dan Albert Jan 07 '19 at 21:25
  • Hey, thank you for your help. The error occurs on a lenovo Tab 10 with Android 6.0.1 and armabi-v7a. In the meantime, i tried the app on my girlfriend's Huawai p20 lite with Android 8 and arm64-v8a and it worked fine, just like on any emulator, witch is why i'm pretty sure now, that this is no cmake-related problem. I'm thinking about downgrading my tablet to lollipop or smth, that's how frustrated i am. Maybe that will help, who knows. – Nils Krautkremer Jan 07 '19 at 21:38
  • 1
    Make sure libjnilibsvm.so is built for the right API level. Not sure how you're building it so I don't know where you need to check, but make sure its minSdkVersion matches yours. It looks like it's 24 or higher, which would explain why it doesn't work on the android-23 device. – Dan Albert Jan 07 '19 at 22:24
  • To be honest, i just included the .aar yctung is providing. His git-rep.-build.gradle states minSdk=16 / 22 i think. Can this really be the cause of this errors even if the app runs on an Api 23 emulator? – Nils Krautkremer Jan 07 '19 at 23:00
  • 1
    The API 23 emulator is x86, not arm (probably; most people don't use the arm emulators because they're very slow). This is an arm specific API that's missing. – Dan Albert Jan 08 '19 at 06:41

0 Answers0