Skip to content

Fix logger on android #15

Closed
Closed

Description

@ortex

Logger doesn't work on android.

A/.rocandroidsin: java_vm_ext.cc:570] JNI DETECTED ERROR IN APPLICATION: JNI GetStaticFieldID called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.github.rocproject.roc.LogLevel" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
    java_vm_ext.cc:570]   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:196)
    java_vm_ext.cc:570]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
    java_vm_ext.cc:570]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    java_vm_ext.cc:570] 
    java_vm_ext.cc:570]     in call to GetStaticFieldID
A/.rocandroidsin: thread.cc:2348] No pending exception expected: java.lang.ClassNotFoundException: Didn't find class "com.github.rocproject.roc.LogLevel" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
    thread.cc:2348]   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:196)
    thread.cc:2348]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
    thread.cc:2348]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    thread.cc:2348] 

This could help: https://developer.android.com/training/articles/perf-jni.html#faq:-why-didnt-findclass-find-my-class

Do your FindClass lookups once, in JNI_OnLoad, and cache the class references for later use. Any FindClass calls made as part of executing JNI_OnLoad will use the class loader associated with the function that called System.loadLibrary (this is a special rule, provided to make library initialization more convenient). If your app code is loading the library, FindClass will use the correct class loader.

Activity

  1. MatteoArella commented on Jun 5, 2020

    @MatteoArella
    Member

    I've cached LogLevel class reference inside JNI_OnLoad 👍

  2. added theissue type on Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions