为 arm64 Android 手机构建应用程序包时在 ApplicationInfo.nativeLibraryDir 中找不到本机库 [英] Native libraries not found in ApplicationInfo.nativeLibraryDir when building app bundle for arm64 Android phone

查看:40
本文介绍了为 arm64 Android 手机构建应用程序包时在 ApplicationInfo.nativeLibraryDir 中找不到本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用从整体式 APK 迁移到应用程序包格式.我需要为 exec() 调用设置 LD_LIBRARY_PATH 环境变量,因此我需要本机库的位置.使用原始 APK 我会调用 getApplicationInfo().nativeLibDir 并且库就在那里.

I am trying to migrate my app from a monolithic APK to the app bundle format. I need to set LD_LIBRARY_PATH environment variable for an exec() call, therefore I need the location of my native libraries. With the original APK I would call getApplicationInfo().nativeLibDir and the libraries were there.

对于应用程序包,它们不是.我可以看到安装了正确的 abi split APK,但由于某种原因库没有被提取.

With the app bundle they are not. I can see the correct abi split APK installed, but for some reason the libraries are not extracted.

我尝试使用 bundletool 和 Google Play 进行安装,

I have tried installing with bundletool and through Google Play,

尝试运行 'ls -alR',我可以清楚地看到目录存在以及拆分的 apk,但库根本没有被提取.我想我可以手动提取它们作为解决方法,但这似乎没有必要..?

Tried to run 'ls -alR' and I can clearly see the directory exists as well as the split apk, but the libraries are simply not extracted. I guess I could extract them manually as a workaround but that would seem unnecessary..?

这是nativeLibPath

genLibraryPath: Dir Contents: /data/app/com.unseenonline-raAFLhJMQpjqWkVdG1Vocg==:
        total 16704
        drwxr-xr-x   4 system system      4096 2019-06-11 12:41 .
        drwxrwx--x 114 system system     12288 2019-06-11 12:41 ..
        -rw-r--r--   1 system system   5688352 2019-06-11 12:41 base.apk
        drwxr-xr-x   3 system system      4096 2019-06-11 12:41 lib
        drwxrwx--x   3 system install     4096 2019-06-11 12:41 oat
        -rw-r--r--   1 system system  11226112 2019-06-11 12:41 split_config.arm64_v8a.apk
        -rw-r--r--   1 system system     35636 2019-06-11 12:41 split_config.en.apk
        -rw-r--r--   1 system system     90443 2019-06-11 12:41 split_config.xxhdpi.apk

        /data/app/com.unseenonline-raAFLhJMQpjqWkVdG1Vocg==/lib:
        total 24
        drwxr-xr-x 3 system system 4096 2019-06-11 12:41 .
        drwxr-xr-x 4 system system 4096 2019-06-11 12:41 ..
        drwxr-xr-x 2 system system 4096 2019-06-11 12:41 arm64

        /data/app/com.unseenonline-raAFLhJMQpjqWkVdG1Vocg==/lib/arm64:
        total 16
        drwxr-xr-x 2 system system 4096 2019-06-11 12:41 .
        drwxr-xr-x 3 system system 4096 2019-06-11 12:41 ..

如您所见,拆分的 apk 已存在,但未提取库.

As you can see the split apks are there but the libraries are not extracted.

库应该被提取到与原始 apk 相同的位置

Libraries should be extracted to the same location as they were with the original apk

推荐答案

默认情况下,从 Android App Bundle 生成的 APK 具有在 Android M/API 级别 23 或更高级别().这不仅通常会减少下载大小,而且还会大大减少设备上应用程序的大小,因为 Android 平台可以直接从 APK 读取本机库,而不必将它们提取到单独的位置.上次 I/O 大会上讨论了如何减小应用的大小以及这对安装数量有何影响,如果您有兴趣更好地理解这一点,他们详细介绍了这是如何工作的.

By default, APKs generated from the Android App Bundle have the native libraries uncompressed on devices with Android M / API level 23 or higher (source). Not only does that often reduce the download size but that also considerably reduce the size of the app on devices since the Android platform can directly read the native libraries from the APK instead of having to extract them to a separate location. There was a talk at last I/O on how to reduce the size of your app and how that impacts install numbers, and they detailed how this works if you're interested in understanding this better.

所以,既然您知道 Google Play 这样做的原因,您有以下选择:

So, now that you know why Google Play is doing this, you have the following options:

  • 您可以选择恢复到原始 APK 行为,这可以通过在 gradle.properties 文件中添加标志 android.bundle.enableUncompressedNativeLibs=false 来完成.这将有效地禁用此优化,从而为 M+ 上的所有用户带来更大的应用大小.

  • You can choose to revert to the original APK behaviour, and this can be done by adding the flag android.bundle.enableUncompressedNativeLibs=false in your gradle.properties file. This will effectively disable this optimization, leading to a bigger size of your app for all your users on M+.

您可以确保 Android 平台加载本机库(例如使用 System.loadLibrary),或者如果您出于某种原因直接自己阅读该库,请阅读它也可以直接从 APK 下载.

You can ensure that the native library is loaded by the Android platform (e.g. using System.loadLibrary) or you if you're reading the library directly yourself for some reason, read it from the APK directly as well.

如果本机库是由您依赖的第三方库加载的,请考虑为他们提交错误以解决此问题,以便他们遵循与平台相同的逻辑.

If the native libraries are loaded by a third party library you're depending on, consider filing a bug for them to address this issue so they follow the same logic as the platform.

希望有所帮助,

这篇关于为 arm64 Android 手机构建应用程序包时在 ApplicationInfo.nativeLibraryDir 中找不到本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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