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

查看:2344
本文介绍了为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.

我尝试使用<$ c安装$ c> 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..?

这是 ls 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天全站免登陆