Search code examples
androidapkminifyandroid-app-bundle

Android app installs from Android Studio, but not externally as .apk. Throws "java.lang.UnsatisfiedLinkError"


Unable to launch Android application when installed externally as .apk. Application installs fine on devices when installed using Android Studio. Logcat shows the error as,

FATAL EXCEPTION: main
Process: com.acme.someprogram, PID: 3806
java.lang.UnsatisfiedLinkError: Can't obtain peer field ID for class com.sun.jna.Pointer
   at com.sun.jna.Native.initIDs(Native Method)
   at com.sun.jna.Native.<clinit>(SourceFile:726)
   at com.sun.jna.Native.r(SourceFile:1)
   at org.vosk.LibVosk.<clinit>(SourceFile)
   at org.vosk.LibVosk.vosk_set_log_level(Native Method)
   at net.acme.someprogram.MainActivity.onCreate(SourceFile:272)
   at android.app.Activity.performCreate(Activity.java:6720)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2622)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2730)
   at android.app.ActivityThread.-wrap12(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1481)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6145)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Gradle app script is,

plugins {
id 'com.android.application'
}

android {
compileSdk 31

defaultConfig {
    applicationId "com.acme.someprogram"
    minSdk 24
    targetSdk 31
    versionCode 19
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
    viewBinding true
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'net.java.dev.jna:jna:5.8.0@aar'
implementation group: 'com.alphacephei', name: 'vosk-android', version: '0.3.32+'
implementation project(':models')
}

Specific suggestions and advice regarding this would be highly appreciated. Thanks in advance.

Update: I have significantly changed the verbiage of this question to more accurately reflect the defining symptoms of the problem as I have identified them.


Solution

  • I disabled code minifying in Gradle and the issue was solved.

    android {
        buildTypes {
            release {
                minifyEnabled false
                ...
            }
        }
    }