• [工作积累] Android dynamic library & JNI_OnLoad


    Bionic libc doesn't load dependencies for current .so file (diff from Windows or Linux)

    so a explicit calling of Java's System.loadLibrary() is needed, in order to load depedency libraries. otherwise the original .so will fail to load.

    JNI_OnLoad will be called mostly on  System.LoadLibrary() or equavilent calls

    System.loadLibrary("gnustl_shared");

    the .so file is loaded & and symbol get loaded by common dynamic library function:

    dlopen

    dlsym

    if the symbol "JNI_OnLoad" is not found in the lib, dalvik will simply do nothing, but a Debug Log: No JNI_OnLoad found in xxx.so, skipping init.

    details at:

     dalvik/vm/Native.c

    NatvieAcitviy: JNI_OnLoad is not get called

    For the startup library speicified by "android.app.lib_name", system will auto-load library on activity startup, but JNI_OnLoad is not get called, only libs loaded by System.loadLibrary() will.

    but you can use native activity and load the library manually for the second time, so that JNI_OnLoad & all other activity binding function is exposed.

    in AndroidManifest.xml:

                <meta-data android:name="android.app.lib_name"
                      android:value="GameLibrary" />

    in Game Activity.java - load it manually:

    1 public class GameActivity extends NativeActivity {
    2     ....
    3     static {
    4         System.loadLibrary("GameLibrary");
    5     }
    6 }
  • 相关阅读:
    人工智能与信号处理--看知乎问答有感.
    nginx 负载均衡及反向代理
    sqlserver 分页查询
    sqlserver 游标使用
    ffmpeg参数编码大全
    C# 阿里云查询、删除文件
    视频分片上传+C#后端合并
    ffmpeg 视频合并
    C# 根据链接提取div内容
    electron-vue 设置cookie
  • 原文地址:https://www.cnblogs.com/crazii/p/4207642.html
Copyright © 2020-2023  润新知