Search code examples
androidandroid-ndkandroid-gradle-plugin

How to disable split APKs in order to test arm only app on x86_64 AVD on Android Studio 2023


I'm trying to build an arm-only app (https://github.com/Mearitek/MeariSdk/tree/MeariSdk-5.0.0) with a fresh Android Studio 2023 install and that does not seem to work because Android Studio seems to insist to create split build APKs and does not find any NDK libraries matching x86_64.

I setup an AVD which allows executing universal binaries with ARM code (all the latest Android x86_64 builds do...) as I did in older Android Studio but here I seem unable to tell it that this AVD is able to process ARM code.

More specifically I get this error:

> Configure project :app
WARNING: Cannot build selected target ABI: x86_64, no suitable splits configured: armeabi-v7a, arm64-v8a;
WARNING: Cannot build selected target ABI: x86_64, no suitable splits configured: armeabi-v7a, arm64-v8a;

Given the error message gradle is clearly trying to "help me" by building a split APK which only contains x86_64 NDK, which is clearly causing it to fail since the project itself does not contain any NDK lib targetting that environment.

The obvious solution would have been to configure Android Studio so that the release/debug build variants create universal binaries (so to allow the AVD to play its magic) however the "build variants" window does not allow me to select ABI/Universal: "build variants" window with missing 3rd column

I tried various suggestions in order to achieve this via gradle config to no avail (e.g. Android App Bundle, Disable Language and Density Split on Base Module or All module) but with fresh Android Studio install I seem to be unable to force building and universal binary.

I've tried commenting the abiFilters but this has the effect to build an APK targetted at x86, thus without any of the needed .so libraries and the app does not work:

loadLibrary failed:dlopen failed: library "libhv.so" not found

so:

  • without abiFilters it compiles and starts but immediately fails because the split APK does not contain any library for x86
  • with abiFilters it compiles but does not build the APKs

As seen from the message: Warning message from Android Studio It would probably be equally good to "explain" to Android Studio that this AVD can run arm software... But I'm not an Android expert and don't know how to do it! :-(


Solution

  • After multiple attempts it turns out I was using an image which indeed does NOT support cross-architecture libraries, thus Android Studio was correctly singaling that. I was using an image:

    • Pixel 3 API 33 x86_64 (Android 13 Tiramisu) image, which is NOT capable to run ARM native libraries

    whereas I resolved by installing:

    • Medium Phone API 31 x86_64 (Android 12 S) image, which is capable to tun ARM binary libraries

    you can easily check if you too are meeting the same problem by drag&drop of an APK which uses ARM libs on the android emulator: if it says it's not able to install because of architecture then the problem is actually the image!