简体   繁体   English

在另一个应用程序中使用已创建的.so文件 - Android NDK

[英]Use created .so file in another application - Android NDK

I have used android - ndk - r8 and followed the LINK to create a .so library. 我使用了android-ndk -r8并按照LINK创建了一个.so库。 Now my aim is to use this library in another project. 现在我的目标是在另一个项目中使用这个库。 Instead of copying the complete source there i just want to use the library. 而不是复制完整的源,我只想使用该库。 I tried to copy & paste the whole libs/armeabi/libAddition.so library to the project root of the another application but the app crashes when i use these library in other application. 我尝试将整个libs / armeabi / libAddition.so库复制并粘贴到另一个应用程序的项目根目录,但是当我在其他应用程序中使用这些库时,应用程序崩溃了。 The library consists of simple addtion of two number logic. 该库包含两个数字逻辑的简单添加。

NOTE Their is no error in application or the .so file and the error in error log is unsatisfiedlinkerror. 注意它们在应用程序或.so文件中没有错误,并且错误日志中的错误不满足linkerror。 Also i dont want to create a library project or anything else i just need to use these .so file in my another project. 此外,我不想创建一个库项目或任何其他我只需要在我的另一个项目中使用这些.so文件。

So what would be the best way to do it? 那么最好的方法是什么呢? I am using Eclipse. 我正在使用Eclipse。

There are two parts to your .so. 你的.so有两个部分。 There is the actual C library you want to use and then there is the JNI glue code. 有你想要使用的实际C库,然后是JNI粘合代码。 I would bet the reason that your app is crashing is because the JNI is referencing the package name from your previous application. 我敢打赌你的应用程序崩溃的原因是因为JNI正在引用你以前的应用程序中的包名。 If you want to create a library that you can use over and over you need to create the library and the JNI separately. 如果要创建可以反复使用的库,则需要单独创建库和JNI。

This post may be useful. 这篇文章可能有用。 I tried it and it worked for me but only if I called System.loadLibrary from the same package name. 我尝试了它,它适用于我,但只有我从相同的包名称调用System.loadLibrary。 Otherwise it thrown an UnsatisfiedLinkError but I didn't looked deeper to know what was wrong. 否则它抛出一个UnsatisfiedLinkError,但我没有深入了解什么是错的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM