born loser
born loser

Reputation: 430

Android Studio: porting old example fails at System.loadLibrary("muse_android");

(again a day wasted..) I can compile and run a 2016 example with updating build.gradle to

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.1"

    defaultConfig {
        applicationId "com.example.muserobo"
        minSdkVersion 14
        targetSdkVersion 30

But when i copy the code into a new project (File->new->New_Project->Empty_Activity), the project compiles successfully but the code

try {
    System.loadLibrary("muse_android");
} catch (UnsatisfiedLinkError var1) {
    Log.v("MUSE", "Failed to load libmuse_android.so. Make sure the jni symbols are accessible somehow.");
}

fails :-( Yes i copied the files libmuse_android.so to app\src\main\jniLibs\armeabi-v7a and libmuse_android.jar to app\libs .

I can delete these files in the updated example by right clicking on them in the project-tree and selecting delete in the context menu. When i then manually copy the files back in place with the windows file explorer (as i did with new project), the example code runs again successfully.

So i am missing some hidden option somewhere that will make the code find that library at runtime or add it to the apk while compiling :-( In other words, simply copying the two files to their destinations is not enough :-/

Here the build.gradle of the new project:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.1"

    defaultConfig {
        applicationId "com.example.muserobo"
        minSdkVersion 14
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Please help save my day :-)

Upvotes: 1

Views: 140

Answers (1)

born loser
born loser

Reputation: 430

Another half of a day wasted on shitty Android. The library libmuse_android.so indeed was packed into the app\build\outputs\apk\debug\app-debug.apk file with Build->Rebuild_Project but was NOT packed into that same apk when choosing Run->Debug_'app'

Solution: Run->Edit_Configuration->app->Depoly: "Default APK" -> "APK from app bundle"

Then an apk that contains the .so is built at app\build\intermediates\extracted_apks\debug\outbase-armeabi_v7a_2.apk and now debugging on my Pixel 1 XL can continue :-)

Shitty Android :-(

Upvotes: 2

Related Questions