0

I've been building my Android Studio project with a native library along side it, and up to this point it has worked just fine. Recently, it started not outputting the native library. Everything still builds successfully, however I don't see any output in the build log related to the native library and I'm unable to run the application on a device as it fails when trying to use the library now with a java.lang.UnsatisfiedLinkError error.

I think this issue might be related to the fact that i switched over to building it as a STATIC library instead of a SHARED library.

My Application level build.gradle:

apply plugin: 'com.android.application' apply plugin: 'io.fabric' apply plugin: 'c' android { compileSdkVersion 25 defaultConfig { applicationId "com.vrazo" minSdkVersion 15 targetSdkVersion 25 versionCode 1529505857 versionName "2018.6.20" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "-latomic" arguments "-DCMAKE_VERBOSE_MAKEFILE=1", "-DANDROID_UNIFIED_HEADERS=ON" } } ndk { // Specifies the ABI configurations of your native // libraries Gradle should build and package with your APK. abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a'// ,x86_64, armeabi //, 'mips', 'mips64' } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "CMakeLists.txt" } } } buildscript { //repositories { // maven { url 'https://maven.fabric.io/public' } //} //dependencies { // The Fabric Gradle plugin uses an open ended version to react // quickly to Android tooling updates // classpath 'io.fabric.tools:gradle:1.+' //} } //repositories { // maven { url 'https://maven.fabric.io/public' } //} //crashlytics { // enableNdk true // manifestPath 'src/main/AndroidManifest.xml' //} dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) implementation project(':library_ripple_backgroud_effect') implementation project(':ccp') implementation 'com.github.bumptech.glide:glide:3.7.0' implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.android.volley:volley:1.0.0' implementation 'com.android.support:appcompat-v7:25.3.1' implementation 'com.android.support:cardview-v7:25.2.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.shawnlin:number-picker:2.4.3' implementation 'com.daasuu:EasingInterpolator:1.0.0' implementation 'com.android.support:design:25.3.1' testImplementation 'junit:junit:4.12' //compile('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') { // transitive = true //} //compile('com.crashlytics.sdk.android:crashlytics-ndk:2.0.4') { // transitive = true //} //compile('io.fabric.sdk.android:fabric:1.4.2@aar') { // transitive = true // } implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' implementation 'com.google.firebase:firebase-core:16.0.0' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3' } apply plugin: 'com.google.gms.google-services' 

My CMakeLists.txt file

# Sets the minimum version of CMake required to build the native # library. You should either keep the default value or only pass a # value of 3.4.0 or lower. cmake_minimum_required(VERSION 3.4.1) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/) add_library ( vtr-lib STATIC src/main/cpp/vtr/vtr_w.c src/main/cpp/vtr/vtrstate_controller_w.c src/main/cpp/vtr/util/vtrutil.c # The API Wrapper Files src/main/cpp/vtr/vtrapi_w.c src/main/cpp/vtr/util/vtrutil.c ) # Import the log library 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 ) # Import the ZLIB Library find_library( # Sets the name of the path variable. zlib-lib # Specifies the name of the NDK library that # you want CMake to locate. z ) # Add the SSL Include Directories based on the current architecture include_directories ( src/main/cpp/libs/${ANDROID_ABI}/include/ src/main/cpp/libs/${ANDROID_ABI}/include/state_machine/ src/main/cpp/vtr/ src/main/cpp/vtr/util/ ) # Add the SSL Library based on the current architecture add_library ( ssl-lib STATIC IMPORTED ) set_target_properties ( ssl-lib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libssl.a ) # Add the Crypto Library based on the current architecture add_library ( crypto-lib STATIC IMPORTED ) set_target_properties ( crypto-lib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/ libs/${ANDROID_ABI}/libcrypto.a ) # Add core vvp library add_library ( vvp-lib STATIC IMPORTED ) set_target_properties( vvp-lib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libvvp.a ) # Add the state machine library add_library( statemachine-lib STATIC IMPORTED ) set_target_properties( statemachine-lib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/ libs/${ANDROID_ABI}/libvtrstatemachine.a ) # Link the libraries to the native library target_link_libraries ( vtr-lib ssl-lib crypto-lib statemachine-lib atomic ${log-lib} ${zlib-lib} vvp-lib ) 
3
  • 1
    You cannot directly load a static native lib from Java. You have to link all your static libs to form a shared (dynamic) library and use System.loadLibrary() in Java to make use of it. Commented Jul 30, 2018 at 1:52
  • @shizhen you're right, that fixed the problem. If you submit it as an answer i will accept it. Commented Jul 30, 2018 at 16:59
  • Glad to hear it helps Commented Jul 31, 2018 at 0:04

1 Answer 1

1

You cannot directly load a static native lib from Java. You have to link all your static libs to form a shared (dynamic) library and use System.loadLibrary() in Java to make use of it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.