Skip to content

[AAB] Feature: Support AAB And extractNativeLibs=false #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shiqos
Copy link

@shiqos shiqos commented Sep 5, 2024

项目未配置 useLegacyPackaging=true 时,
使用AAB安装, 或最低版本为Android M以上的APK
Native库不会从APK中解压, 参考:
https://developer.android.com/guide/topics/manifest/application-element#extractNativeLibs google/bundletool#39

此时xCrash通过 ctx.getApplicationInfo().nativeLibraryDir 获取的目录内容是空的 因此会出现加载xcrash_dumper失败

而通过 PathClassloader.findLibrary(libName) 获取的路径是虚拟路径, 不是真实存在的 因此直接执行也会失败

此时我们参考 Crashpad 的逻辑, 使用linker加载
参考:
https://github.com/chromium/crashpad/blob/main/client/crashpad_client_linux.cc#L114

为了避免大的改动, 默认仅在加载虚拟路径时使用linker, 实际上在所有场景都可以直接通过linker加载

支持外部自定义配置

.setNativeLibPath()
.setLoadNativeWithLinker()

如果外部没有配置,内部会自动查找
参考: AbiPathProvider.java 逻辑

项目未配置 `useLegacyPackaging=true` 时,
使用AAB安装, 或最低版本为Android M以上的APK
Native库不会从APK中解压, 参考:
https://developer.android.com/guide/topics/manifest/application-element#extractNativeLibs
google/bundletool#39

此时xCrash通过 `ctx.getApplicationInfo().nativeLibraryDir` 获取的目录内容是空的
因此会出现加载xcrash_dumper失败

而通过 PathClassloader.findLibrary(libName) 获取的路径是虚拟路径, 不是真实存在的
因此直接执行也会失败

此时我们参考 Crashpad 的逻辑, 使用linker加载
参考:
https://github.com/chromium/crashpad/blob/main/client/crashpad_client_linux.cc#L114

为了避免大的改动, 默认仅在加载虚拟路径时使用linker, 实际上在所有场景都可以直接通过linker加载

支持外部自定义配置
```
.setNativeLibPath()
.setLoadNativeWithLinker()
```

如果外部没有配置,内部会自动查找
参考: AbiPathProvider.java 逻辑
@acecling
Copy link

acecling commented Nov 1, 2024

这个方案在android 9以下不行,大佬针对android 9及以下,采用的是什么方案。

@shiqos
Copy link
Author

shiqos commented Nov 1, 2024

这个方案在android 9以下不行,大佬针对android 9及以下,采用的是什么方案。

我看下~

@Mr-JingShi
Copy link

这个方案在android 9以下不行,大佬针对android 9及以下,采用的是什么方案。

Android 9及以下不支持使用linker方式,所以将so从apk中解压出来,再通过普通方式启动
请参考:shiqos#1

@shiqos
Copy link
Author

shiqos commented Apr 24, 2025

这个方案在android 9以下不行,大佬针对android 9及以下,采用的是什么方案。

Android 9及以下不支持使用linker方式,所以将so从apk中解压出来,再通过普通方式启动 请参考:shiqos#1

你也遇到了么, 我们再aab上Android 9及以下, 使用linker 也没问题呀。。。

@shiqos
Copy link
Author

shiqos commented Apr 24, 2025

这个方案在android 9以下不行,大佬针对android 9及以下,采用的是什么方案。

前面你有同事找过我, 现在咋样了,解决了嘛, 是怎么解决的?

@Mr-JingShi
Copy link

Mr-JingShi commented Apr 25, 2025

这个方案在android 9以下不行,大佬针对android 9及以下,采用的是什么方案。

Android 9及以下不支持使用linker方式,所以将so从apk中解压出来,再通过普通方式启动 请参考:shiqos#1

你也遇到了么, 我们再aab上Android 9及以下, 使用linker 也没问题呀。。。

感谢回复。
我用了Android 8、9进行的测试,都是子进程无法启动。
请确认下,子进程是否启动成功,
(1)子进程main函数第一行加一个打印,看看是否能logcat到。
Android Studio logcat设置为package:mine时无法获取子进程logcat,可以通过cmd或terminal获取
(2) 校验下dump_ok是否为1,是否是走到了崩溃线程的补救方案里。

https://cs.android.com/android/platform/superproject/+/android-10.0.0_r1:bionic/linker/linker_main.cpp;l=659-677
image
从源码看,只有Android 10才开始支持path.zip!/program

@Mr-JingShi
Copy link

Mr-JingShi commented Apr 25, 2025

这个方案在android 9以下不行,大佬针对android 9及以下,采用的是什么方案。

前面你有同事找过我, 现在咋样了,解决了嘛, 是怎么解决的?

我刚遇到此问题,和他并不认识哈。
我把xcrash_dumper从apk中解压出来,然后再通过execl启动,可以正常启动子进程。
粗鲁估算解压xcrash_dumper大概100ms左右,且一次解压成功后不需要再次解压。
xcrash_dumper经过strip后112K左右,占用磁盘空间不大。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants