beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.69k stars 375 forks source link

Add option to configure Android ABIs #808

Open mhsmith opened 2 years ago

mhsmith commented 2 years ago

Generated APKs and AABs currently include the following ABIs:

We can't drop armeabi-v7a yet, because there are still too many 32-bit devices in use (see https://github.com/chaquo/chaquopy/issues/709). However, we were OK to drop 32-bit x86 because we set our minimum API level to 26 (https://github.com/beeware/briefcase-android-gradle-template/pull/49), and 64-bit emulator images have been available since level 21. Since BeeWare developers will need to use a 64-bit emulator image anyway to test on the current version of Android, requiring them to do the same on the other versions is no great inconvenience. And omitting x86 reduces the APK size and makes it faster to build and install.

Anyway, there are legitimate reasons for developers to want to change the set of available ABIs, so we should make this configurable in pyproject.toml. See https://github.com/beeware/briefcase-android-gradle-template/pull/52#discussion_r935822715 for discussion of possible approaches.

mhsmith commented 2 years ago

Other open issues that may involve updating the Android template:

freakboy3742 commented 2 years ago

+1.

Flagging this as "first timers" because the actual change isn't especially complex:

For example, a project configuration of:

[tool.briefcase.app.myapp.android]
android_abis = ['arm64-v8a', 'x86_64']

would result in a build.gradle file that contains:

...
    defaultConfig {
        applicationId "com.example.helloworld"
...
        ndk {
            abiFilters 'arm64-v8a', 'x86_64'
        }

However, if the user doesn't specify android_abis, the ndk block would not be included.

mhsmith commented 2 years ago

The above comment is valid for the current Rubicon template. After we switch to Chaquopy, the abiFilters setting will be compulsory, because the Chaquopy plugin requires it. I did this because defaulting to all 4 ABIs could make the APK too large, so I thought it was better to force the user to be explicit about what they wanted.

mhsmith commented 1 year ago

This can now be done using the build_gradle_extra_content setting. For example, to include the 64-bit ABIs only:

build_gradle_extra_content = "android.defaultConfig.ndk.abiFilters = ['arm64-v8a', 'x86_64']"
freakboy3742 commented 1 year ago

@mhsmith I'm not sure we can close this. Selecting target platforms isn't an especially common use case, but it's high on the list of "optional things people are may want to do to their project". An explicit setting for this means we're protected from any format changes that Gradle introduces into the configuration file format, as we're capturing a "first order" user configuration.

At the very least, it's worth capturing as documentation (possibly as a section in the docs on briefcase_gradle_extra_content capturing "common use cases" (along with the extract_packages use case).