本文介绍了CLI在DalvikVM上失败JNI LIB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Android上运行的Java应用程序的命令行版本(是的,我知道这不是微不足道的)。

I need to run a command line version of java application on Android(Yeah I know it's not trivial).

我想它使用Dalvikvm启动,它实际上开始,但后来的某个地方,因为它开始使用android.util.log并抛出该异常我的code失败。

I'm trying to start it using Dalvikvm, it actually starts but somewhere later my code fails because it starts using android.util.log and throws this exception.

java.lang.UnsatisfiedLinkError: println_native
    at android.util.Log.println_native(Native Method)
    at android.util.Log.i(Log.java:159)
    at org.slf4j.impl.AndroidLogger.info(AndroidLogger.java:151)
    at org.gihon.client.TunnelingClient.<init>(TunnelingClient.java:62)
    at org.gihon.client.CLI.main(CLI.java:95)
    at dalvik.system.NativeStart.main(Native Method)

我尝试设置环境变量,我设置了LD_LIBRARY_PATH和BOOTCLASSPATH变量。我甚至尝试preloading liblog与LD_ preLOAD,但没有固定的。看来,什么是错的/不同与dalvikvm设置环境的方式。

I tried setting the environment variables, I set the LD_LIBRARY_PATH and the BOOTCLASSPATH variables. I even tried preloading liblog with LD_PRELOAD but nothing fixed that.It seems that something is wrong/different with the way dalvikvm sets the environment.

推荐答案

问得好!我只好掏了一下摸不着头脑。

Good question! I had to dig a bit to figure this out.

有对JNI方法libandroid_runtime.so没有得到默认绑定,当你使用dalvikvm命令摆。不幸的是,你不能只是做一个的System.loadLibrary(android_runtime),因为这实际上并不绑定所有的本地方法。

There are a slew of JNI methods in libandroid_runtime.so that don't get bound by default, when you're using the dalvikvm command. Unfortunately, you can't just do a System.loadLibrary("android_runtime"), because this doesn't actually bind all the native methods.

然而,一些挖后,原来有一个内部的,非公开的,不保证有类称为com.android.internal.util.WithFramework,其目的是加载libandroid_runtime.so并结合其所有JNI的方法。

However, after some digging, it turns out there is an internal, non-public, not guaranteed to be there class called com.android.internal.util.WithFramework, whose purpose is to load libandroid_runtime.so and bind all its JNI methods.

要使用它,只是把 com.android.internal.util.WithFramework 中的类名称的前面,在dalvikvm命令,像这样:

To use it, just throw com.android.internal.util.WithFramework in front of your class name, on the dalvikvm command, like so:

dalvikvm -cp /some/path/classes.dex com.android.internal.util.WithFramework my.example.cls "This is an argument"

这篇关于CLI在DalvikVM上失败JNI LIB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 21:29