Skip to content

Support ABI splits#281

Merged
runningcode merged 5 commits into
runningcode:masterfrom
jschear:js/support_abi_splits
Nov 30, 2021
Merged

Support ABI splits#281
runningcode merged 5 commits into
runningcode:masterfrom
jschear:js/support_abi_splits

Conversation

@jschear

@jschear jschear commented Oct 27, 2021

Copy link
Copy Markdown
Contributor

Background

The Android Gradle Plugin has a feature called "APK splits": it can generate multiple APKs for a single build variant based on a few well-defined dimensions, such as device ABI or screen density. When APK splits are enabled, the collection returned by BaseVariant#getOutputs() contains multiple APK files.

Currently, an app that uses APK splits will experience two issues:

  • When using the Fladle plugin, if the debugApk path is not specified and instead derived from the specified variant, the APK split that is selected is unspecified -- it will be the first in the BaseVariant#getOutputs() collection.
  • When using the Fulladle plugin, each split APK for an application module will be added to additional-app-test-apks separately. Here's what the generated flank yml looks like on our project:
> Task :printYml
gcloud:
  app: /<path>/app/build/outputs/apk/internal/debug/app-internal-arm64-v8a-debug.apk
  test: /<path>/app/build/outputs/apk/androidTest/internal/debug/app-internal-debug-androidTest.apk
# ...
flank:
  # ...
  additional-app-test-apks:
    - app: /<path>/app/build/outputs/apk/internal/debug/app-internal-armeabi-v7a-debug.apk
      test: /<path>/app/build/outputs/apk/androidTest/internal/debug/app-internal-debug-androidTest.apk

    - app: /<path>/app/build/outputs/apk/internal/debug/app-internal-x86-debug.apk
      test: /<path>/app/build/outputs/apk/androidTest/internal/debug/app-internal-debug-androidTest.apk

    - app: /<path>/app/build/outputs/apk/internal/debug/app-internal-x86_64-debug.apk
      test: /<path>/app/build/outputs/apk/androidTest/internal/debug/app-internal-debug-androidTest.apk

    - test: /<path>/features/channel-browser/build/outputs/apk/androidTest/release/channel-browser-release-androidTest.apk

    - test: /<path>/tooling/benchmarks/android/benchmark/build/outputs/apk/androidTest/release/benchmark-release-androidTest.apk

(Note that all APK splits of app-internal-<ABI>-debug.apk are being tested.)

Supporting ABI splits

This PR adds an abi property to FladleConfig to allow users to choose which ABI to use when splits are enabled. (Note that this doesn't add a screen density option -- hopefully people aren't using those as often 😅 ).

With this change, the resulting Fulladle yml in our project no longer contains the additional APK splits.

> Task :printYml
gcloud:
  app: /<path>/app/build/outputs/apk/internal/debug/app-internal-x86-debug.apk
  test: /<path>/app/build/outputs/apk/androidTest/internal/debug/app-internal-debug-androidTest.apk
  # ...
flank:
  # ...
  additional-app-test-apks:
    - test: /<path>/features/channel-browser/build/outputs/apk/androidTest/release/channel-browser-release-androidTest.apk

    - test: /<path>/tooling/benchmarks/android/benchmark/build/outputs/apk/androidTest/release/benchmark-release-androidTest.apk

testedVariant.outputs
.matching { it.isExpectedAbiOutput(flankGradleExtension) }
.configureEach app@{
if (addedTestsForModule) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this check inside of the testedVariant.outputs loop was the key to not adding each split APK to additional-app-test-apks.

} else {
// Otherwise, let's just add it to the list.
if (project.isAndroidAppModule) {
yml.appendln("- app: ${[email protected]}")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appendln is deprecated in favor of appendLine.

@sramakrishnan11

Copy link
Copy Markdown

@runningcode Can you help with reviewing and approving this change. Thanks!

@runningcode runningcode left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It would be nice to also add this to the documentation. docs/configuration.md and the release notes docs/changelog.md.

For my understanding this allows you to test one split at a time. If you want to configure mulitple splits, you could do by using separate configs.

withAbiSplit: Boolean = false,
withFladleConfig: String = "",
withTask: String = "runFlank",
dryRun: Boolean = true,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this addition! thanks.

}

@Test
fun testAbiSplitsWithVariants() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the test with variants as well!

@Test
fun testAbiSplitsWithVariants() {
val result = setUpDependOnAssemble(true, withFlavors = true, withAbiSplit = true, withTask = "printYml", dryRun = false)
// app: /private/var/folders/m2/7q9pbw453p19bpl150ntdfr40000gp/T/junit6930313466230424292/build/outputs/apk/chocolate/debug/junit6930313466230424292-chocolate-x86-debug.apk

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this comment isn't necessary

buildscript {
repositories {
google()
jcenter()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove jcenter() here?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for removing this everywhere 👍

@runningcode
runningcode merged commit 2fb685b into runningcode:master Nov 30, 2021
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