如何在 64 位 Android-L 平台上使用 32 位原生库 [英] how to use 32bit native libraries on 64 bit Android-L platform

查看:55
本文介绍了如何在 64 位 Android-L 平台上使用 32 位原生库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 AOSP(Kitkat) 编译的 Android 应用程序作为 android 系统应用程序,它运行良好.我的应用程序依赖于使用 Android-NDK 编译为 32 位库的本机代码.我正在我的 android 应用程序 libs/armeabi 文件夹中复制本机库,然后在 AOSP 中构建我的 android 应用程序(我还修改了 device.mk 以将我的库复制到 libs/armeabistrong>/system/lib 文件夹).在 Android Kitkat 上一切正常.

I have a Android application which i compiled with AOSP(Kitkat) as android system application and it was running fine. My application is dependent on native code compiled with Android-NDK as 32 bit libraries. I am copying native libraries inside my android applications libs/armeabi folder and then building my android application in AOSP(I have also modified device.mk to copy my libs in the /system/lib folder). Everything is working fine on Android Kitkat.

当我在 Android-L(64 位平台)上移植我的应用程序时,我无法从 Android 应用程序加载我的本机库,错误就像 -

When i ported my application on Android-L(64bit platform) then i am not able to load my native libraries from Android application and error is like -

java.lang.UnsatisfiedLinkError: dlopen failed: "libfoobar.so" is 32-bit 而不是 64-bit

我正在使用以下 java 代码加载本机库-

I am using following java code to load native library-

        if ( ENABLE_ANDROID_INTEGRATION )
        {
            System.load("/system/lib/libfoobar.so");
        }
        else
        {
            System.loadLibrary("foobar");
        }

当我使用 AOSP 构建代码时,ENABLE_ANDROID_INTEGRATIONtrue

When i am building my code with AOSP then ENABLE_ANDROID_INTEGRATION is true

更有趣的是,当我关闭 ENABLE_ANDROID_INTEGRATION 并在 Eclipse 中构建我的应用程序时,在 AOSP 之外作为一个普通的可下载"应用程序,然后我的应用程序在 64 位 Android 平台上运行良好.

More interestingly when i turned off ENABLE_ANDROID_INTEGRATION and build my application in Eclipse, outside AOSP as a normal "downloadable" application then my application is running fine on 64bit Android platform.

我想知道的 - 如何将我的应用程序构建为具有 32 位库(即 AOSP 构建)的原生 Android 系统应用程序,适用于 64 位 Android 平台?

What i want to know - how can i build my application as a native android system application with 32 bit libraries(that means AOSP build) for 64 bit Android platform?

我的尝试 - 我在我的 android 应用程序的 Android.mk 文件中使用了 LOCAL_32_BIT_ONLY = true 标志,但它接缝没有用.可能我不完全了解这个标志的使用.

What i have tried - I used LOCAL_32_BIT_ONLY = true flag in my android application's Android.mk file, but it seams it is not useful. May be i am not fully aware of this flag use.

因为我的时间不多了,所以我更喜欢在这里分组而不是 RnD 发布这个问题.如果有人遇到这个问题,请指导.

As i am running out of time so i preferred to post this question here in group instead of RnD. If anyone faced this problem then please guide.

问候,梅拉吉

推荐答案

它作为第三方应用程序安装时有效的原因是,在安装时,包管理器会扫描 APK 并检查它是否使用本机库,并且如果找到,它会存储他们使用的 ABI(因为它只为一个 ABI 安装库,因此需要将有关选择的信息存储在某处).

The reason why it works when installed as a third party application, is that on installation, the package manager scans the APK and checks if it uses native libraries, and if such are found, it stores which ABI they used (since it only installs libraries for one single ABI, so the info about which choice was made needs to be stored somewhere).

对于使用/system/lib 中的库在系统范围内安装的应用程序,不清楚该特定应用程序依赖于/system/lib 中的某些特定于应用程序的库(在 64 位版本中不可用)/system/lib64),所以包/应用程序管理器无法知道这个特定的应用程序需要特定的 ABI 并因此在 64 位模式下运行.

For an application that is installed system wide with the libraries in /system/lib, it's not clear that this particular application depends on some app specific libs in /system/lib (that aren't available in a 64 bit version in /system/lib64), so the package/application manager can't know that this particular app requires a specific ABI and thus runs it in 64 bit mode.

设置 LOCAL_32_BIT_ONLY 可能只影响它是否应该在 32 位模式下编译,而不是它应该以哪种方式运行.

Setting LOCAL_32_BIT_ONLY probably only affects whether it should be compiled in 32 bit mode, not in which way it should be run.

http://www.slideshare.net/hiddenorly/investigation-result-on-64-bit-support-in-aosp 似乎建议应用的本机库应该进入/system/lib/apkname,但在实际的 Android 5.0 系统上似乎并非如此.相反,这些库似乎在/system/app/appname/lib/abiname 中.一些应用程序似乎有多种架构的原生库(例如arm"和arm64"作为 abiname),而其他应用程序只有一个架构(这将强制在该 ABI 中启动进程模式).

An old (and probably outdated) report at http://www.slideshare.net/hidenorly/investigation-result-on-64-bit-support-in-aosp seems to suggest that the native libraries for apps should go into /system/lib/apkname, but this doesn't seem to be true on an actual Android 5.0 system. Instead, the libs seem to be in /system/app/appname/lib/abiname. Some apps seem to have native libs for multiple architectures (e.g. both "arm" and "arm64" as abiname), while others only have one single architecture (which would force the process to be started in that ABI mode).

所以我认为您需要更改安装本机库的机制(您说您手动修改了 device.mk) - 我不熟悉如何将自己的应用程序构建为 AOSP 构建的一部分,但我建议尝试查看现有的捆绑应用程序是如何执行的,此提交可能与此相关:https://android.googlesource.com/platform/packages/apps/Terminal/+/1a161f75%5E%21/

So I think you need to alter the mechanism for how you install your native libraries (you said you manually modified device.mk) - I'm not familiar with how to build own apps as part of an AOSP build, but I'd recommend trying to look at the existing bundled apps how they do it, this commit may be related: https://android.googlesource.com/platform/packages/apps/Terminal/+/1a161f75%5E%21/

这篇关于如何在 64 位 Android-L 平台上使用 32 位原生库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆