[Android] Something's went wrong with pytorch_android-1.4.0-SNAPSHOT

Tried to set up HelloWorldApp (https://github.com/pytorch/android-demo-app) with the most latest version of PyTorch built from source.
After a little bit of struggling with gradle build I’ve ended up with crash on devices.

Here is the build.gradle :app

apply plugin: 'com.android.application'

repositories {
    jcenter()
    flatDir {
        dirs 'libs'
    }
}

android {
    packagingOptions {
        pickFirst "**/libfbjni.so"
    }
    compileSdkVersion 28
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "org.pytorch.helloworld"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    } 
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0'
    // implementation 'org.pytorch:pytorch_android:1.3.0'
    // implementation 'org.pytorch:pytorch_android_torchvision:1.3.0'
    implementation(name:'pytorch_android-1.4.0-SNAPSHOT', ext:'aar')
    implementation(name:'pytorch_android_torchvision-1.4.0-SNAPSHOT', ext:'aar')
    implementation(name:'pytorch_android_fbjni-1.4.0-SNAPSHOT', ext:'aar')
}

Note: .aar libs are present

Crash stacktrace

2019-10-04 22:31:16.059 16203-16203/org.pytorch.helloworld E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.pytorch.helloworld, PID: 16203
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/soloader/nativeloader/NativeLoader;
        at org.pytorch.Module.<init>(Module.java:27)
        at org.pytorch.Module.load(Module.java:23)
        at org.pytorch.helloworld.MainActivity.onCreate(MainActivity.java:39)
        at android.app.Activity.performCreate(Activity.java:8068)
        at android.app.Activity.performCreate(Activity.java:8056)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3757)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3955)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2392)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:213)
        at android.app.ActivityThread.main(ActivityThread.java:8147)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.soloader.nativeloader.NativeLoader" on path: DexPathList[[zip file "/data/app/org.pytorch.helloworld-eCefKQPfLWFqNPNZZUphIA==/base.apk"],nativeLibraryDirectories=[/data/app/org.pytorch.helloworld-eCefKQPfLWFqNPNZZUphIA==/lib/arm64, /data/app/org.pytorch.helloworld-eCefKQPfLWFqNPNZZUphIA==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64, /hw_product/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at org.pytorch.Module.<init>(Module.java:27) 
        at org.pytorch.Module.load(Module.java:23) 
        at org.pytorch.helloworld.MainActivity.onCreate(MainActivity.java:39) 
        at android.app.Activity.performCreate(Activity.java:8068) 
        at android.app.Activity.performCreate(Activity.java:8056) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3757) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3955) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2392) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:213) 
        at android.app.ActivityThread.main(ActivityThread.java:8147) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 

May be we should not rely on unstable version but module = Module.load() is a core feature :slightly_smiling_face:

1 Like

There is still an issue.
Here’s what I’ve noticed except an issue pytorch_android_torchvision-1.4.0-SNAPSHOT.aar works with org.pytorch:pytorch_android:1.3.0 from remote repo.
The problem occurs only with pytorch_android-1.4.0-SNAPSHOT.aar

Hello Emil,

If you have not changed the source - you can use our nightly builds that are published every night to nexus sonatype maven repo.

To use it:

repositories {

maven {
url “https://oss.sonatype.org/content/repositories/snapshots
}
}

dependencies {
implementation ‘androidx.appcompat:appcompat:1.1.0’
implementation ‘org.pytorch:pytorch_android:1.4.0-SNAPSHOT’
implementation ‘org.pytorch:pytorch_android_torchvision:1.4.0-SNAPSHOT’
}

I rechecked HelloWorldApp with the latest published 1.4.0-SNAPSHOT - it works fine.

  1. About your failure:

It looks like that in your aar you do not have dependency: ( com.facebook.soloader:nativeloader )
which was added after 1.3.0 release:


Please add it manually:
implementation ‘com.facebook.soloader:nativeloader:0.8.0’

In case of using maven dependency gradle will parse pom file that has this dependency and add it automatically. For manual aar files we have to add all transitive dependencies manually.