Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java-runtime] Simplify and fix split configs detection (#9378)
We use [`ApplicationInfo.splitSourceDirs`][0] to detect whether the application uses [split config `.apk` files][1]. Those files are created by Android when an `.aab` is used to deploy application, e.g. via the Google Play Store or manually: % dotnet new android % dotnet build -c Release % java -jar /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.94/tools/bundletool.jar \ build-apks --bundle bin/Release/net8.0-android/*-Signed.aab \ --output=app.apks --connected-device \ --aapt2 /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.94/tools/Darwin/aapt2 # app.apks contains the "split" apk files. # can manually install app.apks by using `bundletool.jar install-apks`: % java -jar /usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.94/tools/bundletool.jar \ install-apks --apks=app.apks When they are present, the "base" `.apk` file in `splits/base-master.apk` doesn't contain any `lib/` directories and we can simply skip scanning it for those entries, thus saving on startup time. (The `splits/base-<ABI>.apk` file contains the native libraries of interest to us.) We used to check whether there are more than one entry in `splitSourceDirs`, which used to be the case, but it seems that recent Android versions (at least API-33 and newer) can have just a single entry in the array. Because of that, we were scanning all the `.apk` files on those Android versions, wasting time at startup. Fix the check by probing whether the array exists and contains at least a single entry. Additionally, remove API-21 checks, since this is our lowest supported API level. [0]: https://developer.android.com/reference/android/content/pm/ApplicationInfo#splitSourceDirs [1]: https://developer.android.com/guide/app-bundle
- Loading branch information