pytorch / pytorch/executorch

[Android] Error running a transformer decoder-based neural network

Open
#8,665 51 comments 0 reactions 1 assignee View on GitHub

@kirklandsign is already working on this.

Since Feb 25, 2025.

module: android module: user experience triaged
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

Hi,

@kirklandsign I have been developing on Android for more than 15 years. I am familiar with dependencies etc., etc. The issue 8636 had to do with packaging.

I guess you did not see my last comment in
https://github.com/pytorch/executorch/issues/8636

Here it is again:

Hi Update https://github.com/pytorch/executorch/pull/2

I worked around the classNotFound exception by creating a java.org.pytorch.executorch package containing all the source files from
executorch/extension/android/src/main/java/org/pytorch/executorch

Now execution fails producing the error log reported below.

I built ```libexecutorch.so``` following the instructions in
https://pytorch.org/executorch/stable/demo-apps-android.html

Package name is the same as expected (and used in the android demo app), i.e. ```org.pytorch.executorch```

The dependencies are
                implementation 'com.facebook.fbjni:fbjni-java-only:0.2.2'
                implementation 'com.facebook.soloader:nativeloader:0.10.5'

as in the android demo app

At this point, I am at a loss as to what I am doing wrong and what I should try next.

Should I add and android module to my project just as there is one in the android demo app. In the android demo app, the android module contains all the modules necessary to use the executorch runtime (e.g. NativePeer) in the application.

I think the issue may be related to multi-project set-up which I do not use in my application (although I do have multiple modules within the project.

Generally speaking, I still have the sense that the set-up to use the executorch runtime on Android applications could/should be simpler, for example not requiring the use of the wrapper modules in org.pytorch.executorch

Please let me know if you need additional information.

Thanks

ERROR LOG

02-23 16:41:41.176: W/libc(25151): Access denied finding property "ro.mediatek.platform"
02-23 16:41:41.176: W/libc(25151): Access denied finding property "ro.chipname"
02-23 16:41:41.177: E/audit(1210): type=1400 audit(1740325301.170:52396): avc:  denied  { read } for  pid=25151 comm="Thread-2" name="u:object_r:media_plat_prop:s0" dev="tmpfs" ino=315 scontext=u:r:untrusted_app_30:s0:c45,c258,c512,c768 tcontext=u:object_r:media_plat_prop:s0 tclass=file permissive=0 SEPF_SM-S908B_12_0001 audit_filtered
02-23 16:41:41.177: E/audit(1210): type=1400 audit(1740325301.170:52397): avc:  denied  { read } for  pid=25151 comm="Thread-2" name="u:object_r:chipname_prop:s0" dev="tmpfs" ino=165 scontext=u:r:untrusted_app_30:s0:c45,c258,c512,c768 tcontext=u:object_r:chipname_prop:s0 tclass=file permissive=0 SEPF_SM-S908B_12_0001 audit_filtered
02-23 16:41:41.179: D/nativeloader(25151): Load /data/app/~~CzYQ5jB-bXszoW-cWE7uUg==/com.android.contextq-B_Rwji2_VyK2Jx3NvUwN1A==/base.apk!/lib/arm64-v8a/libexecutorch.so using ns clns-5 from class loader (caller=/data/app/~~CzYQ5jB-bXszoW-cWE7uUg==/com.android.contextq-B_Rwji2_VyK2Jx3NvUwN1A==/base.apk): ok
02-23 16:41:41.179: W/lNetworkService(25151): CheckJNI: method to register "initHybrid" not in the given class. This is slow, consider changing your RegisterNatives calls.
02-23 16:41:41.183: E/lNetworkService(25151): ----- class 'Lorg/pytorch/executorch/NativePeer;' cl=0x140133a8 -----
02-23 16:41:41.183: E/lNetworkService(25151):   objectSize=240 (224 from super)
02-23 16:41:41.183: E/lNetworkService(25151):   access=0x0000.0000
02-23 16:41:41.183: E/lNetworkService(25151):   super='java.lang.Class<java.lang.Object>' (cl=0x0)
02-23 16:41:41.183: E/lNetworkService(25151):   interfaces (1):
02-23 16:41:41.183: E/lNetworkService(25151):      0: java.lang.Class<org.pytorch.executorch.INativePeer> (cl=0x140133a8)
02-23 16:41:41.183: E/lNetworkService(25151):   vtable (2 entries, 11 in super):
02-23 16:41:41.183: E/lNetworkService(25151):      0: org.pytorch.executorch.EValue org.pytorch.executorch.NativePeer.forward(org.pytorch.executorch.EValue[])
02-23 16:41:41.183: E/lNetworkService(25151):      1: void org.pytorch.executorch.NativePeer.resetNative()
02-23 16:41:41.183: E/lNetworkService(25151):   direct methods (3 entries):
02-23 16:41:41.183: E/lNetworkService(25151):      0: void org.pytorch.executorch.NativePeer.<clinit>()
02-23 16:41:41.183: E/lNetworkService(25151):      1: void org.pytorch.executorch.NativePeer.<init>(java.lang.String, java.util.Map)
02-23 16:41:41.183: E/lNetworkService(25151):      2: com.facebook.jni.HybridData org.pytorch.executorch.NativePeer.initHybrid(java.lang.String, java.util.Map)
02-23 16:41:41.183: E/lNetworkService(25151):   instance fields (1 entries):
02-23 16:41:41.183: E/lNetworkService(25151):      0: com.facebook.jni.HybridData org.pytorch.executorch.NativePeer.mHybridData
02-23 16:41:41.183: E/lNetworkService(25151): Failed to register native method org.pytorch.executorch.NativePeer.initHybrid(Ljava/lang/String;I)Lcom/facebook/jni/HybridData; in /data/data/com.android.contextq/code_cache/.overlay/base.apk/classes14.dex
02-23 16:41:41.184: E/log(25151): error java.lang.NoSuchMethodError: no static or non-static method "Lorg/pytorch/executorch/NativePeer;.initHybrid(Ljava/lang/String;I)Lcom/facebook/jni/HybridData;"
02-23 16:41:41.185: A/lNetworkService(25151): java_vm_ext.cc:616] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.NoSuchMethodError: no static or non-static method "Lorg/pytorch/executorch/NativePeer;.initHybrid(Ljava/lang/String;I)Lcom/facebook/jni/HybridData;"
02-23 16:41:41.185: A/lNetworkService(25151): java_vm_ext.cc:616] (Throwable with no stack trace)
02-23 16:41:41.185: A/lNetworkService(25151): java_vm_ext.cc:616] 
02-23 16:41:41.185: A/lNetworkService(25151): java_vm_ext.cc:616]     in call to NewGlobalRef
02-23 16:41:41.185: A/lNetworkService(25151): java_vm_ext.cc:616]     from java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.Class)

cc @kirklandsign @cbilgin @mergennachin @byjlw

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.