zoukankan      html  css  js  c++  java
  • [工作积累] 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 }
  • 相关阅读:
    小程序 新建项目底部tabbar
    HBuild 连接安卓手机
    jquery tab切换
    VUE 项目运行
    VUE 创建element项目
    VUE环境搭建、创建项目、vue调试工具
    HBuild 连接苹果手机
    javascript五种基本类型
    SASS 简单实用
    redis基础02-redis的5种对象数据类型
  • 原文地址:https://www.cnblogs.com/crazii/p/4207642.html
Copyright © 2011-2022 走看看