[英]Create a .jar from a .dll
I'm currently trying to create a .jar from a .dll, in order to use it on Android applications. 我目前正在尝试从.dll创建.jar,以便在Android应用程序上使用它。 I'm quite new with this technology, so I'll tried to be as clear as possible.
我对这项技术还很陌生,所以我会尽量保持清晰。
I have 3 distinct parts: 我有3个不同的部分:
This part works pretty well. 这部分效果很好。 I created a main test and I get all the information from the API in Java.
我创建了一个主测试,并从Java中的API获取了所有信息。 But now, I would like to create a .jar file that I can use on Android and here comes the crows...
但是现在,我想创建一个可以在Android上使用的.jar文件,乌鸦来了...
I tried many ways, from the simple .jar export, to the One-Jar method, but nothing worked. 我尝试了很多方法,从简单的.jar导出到One-Jar方法,但没有任何效果。 I always have a link error on my android platform (functions are recognized on the .jar, but their implementations are not).
我的android平台上总是存在链接错误(.jar上可以识别功能,但其实现无法识别)。
So here is my question, how to create a kind of 'static library' in a .jar that I can use on Android? 所以这是我的问题,如何在可以在Android上使用的.jar中创建一种“静态库”?
I hope I was clear enough, don't hesitate to ask me more details. 我希望我足够清楚,不要犹豫,问我更多细节。
Thank you for your help! 谢谢您的帮助!
EDIT: 编辑:
I tried with an Android Library project and my problem is always coming from my loadLibrary() function: 我尝试了一个Android Library项目,而我的问题总是来自我的loadLibrary()函数:
public class MyWrapper {
static {
System.loadLibrary("MyWrapper");
}
public static native int getNegative(int p_number);
public static native int getPositive(int p_number);
}
Every things works fine on my library, but when I use it in android application, I always get this error: 一切都在我的库中正常运行,但是当我在android应用程序中使用它时,我总是会收到此错误:
01-27 11:31:29.565: E/AndroidRuntime(7089): FATAL EXCEPTION: main
01-27 11:31:29.565: E/AndroidRuntime(7089): Process: com.example.wrappertest, PID: 7089
01-27 11:31:29.565: E/AndroidRuntime(7089): java.lang.UnsatisfiedLinkError: Couldn't load MyWrapper from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.wrappertest-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.wrappertest-2, /vendor/lib, /system/lib]]]: findLibrary returned null
My library cound't be created as static library, to keep the link on the .dll? 我的库无法创建为静态库,以将链接保留在.dll上吗?
A .dll file is usually windows specific. .dll文件通常是Windows特定的。 If you're wanting to load native code on Android you'll have to look into using the Native Development Kit.
如果要在Android上加载本机代码,则必须考虑使用本机开发套件。 The specifics of using the NDK is a bit beyond what can be explained here, but the Android Developer website provides a decent starting point at http://developer.android.com/tools/sdk/ndk/index.html
使用NDK的细节超出了此处的解释范围,但是Android Developer网站在http://developer.android.com/tools/sdk/ndk/index.html提供了不错的起点
As for the jar itself, you may want to look into building an Android Library Project instead. 至于jar本身,您可能需要考虑构建一个Android Library Project。 This is essentially a means of packaging a jar with some assets (including native libraries) which can be used by an Android Application project.
从本质上讲,这是一种将带有一些资产(包括本机库)的jar打包的方法,供Android应用程序项目使用。
ndk-build
ndk-build
编译您的librarie ndk-build
and create Android.mk
and Application.mk
in the jni folder ndk-build
gradle并在jni文件夹中创建Android.mk
和Application.mk
.so
library and pre build it on the Android.mk
.so
库并在Android.mk
上预先构建 ndk-build
manually and its done ndk-build
并完成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.