Skip to content

Auto-detected APK paths are wrong with multiple flavor dimensions or a custom outputFileName (0.21.0, AGP 9) #505

Open

Description

@squetched

Description

Human note: Apologies for an llm generated issue but I have proof-read it and verified it as far as I could

Since 0.21.0, findDebugAndInstrumentationApk (FladlePluginDelegate.kt) builds APK paths from AGP's default naming instead of reading the real output location (0.19.0 used ApkVariantOutput.outputFile). This produces non-existent paths in two cases:

  1. Multiple flavor dimensions. Flavors are joined with / (flavorPath), but AGP uses the combined flavor name as a single directory.

    • Fladle: build/outputs/apk/something/all/debug/app-something-all-debug.apk
    • AGP: build/outputs/apk/somethingAll/debug/app-something-all-debug.apk
    • Same for the test APK (androidTest/something/all/debug vs androidTest/somethingAll/debug).
    • Not visible with a single dimension (e.g. freeDebug), where both are free/debug.
  2. Custom VariantOutput.outputFileName. The file name is always $archivesName[-$flavor][-$abi]-$buildType.apk, ignoring an output file name set via the Variant API:

    androidComponents.onVariants { variant ->
        variant.outputs.forEach { it.outputFileName.set("${variant.name}-$versionName.apk") }
    }

Flank then fails with:

'.../build/outputs/apk/debug/sample-debug.apk' from app doesn't exist

Versions

  • Fladle 0.21.0
  • AGP 9.5.0
  • Gradle 9.9.1

Suggested fix

In findDebugAndInstrumentationApk:

  • Use variant.flavorName (combined name) instead of joining productFlavors with / for the directory, for both app and test APKs.
  • Use output.outputFileName for the app APK name, e.g.
    config.debugApk.set(
        buildDir.zip(output.outputFileName) { dir, fileName ->
            dir.file("outputs/apk/$appApkDirPath/$fileName").asFile.absolutePath
        }
    )
    (outputFileName is a Property<String> and can be read lazily, so it also picks up values set by callbacks registered after Fladle's.)

Workaround

Set debugApk / instrumentationApk explicitly, e.g. "$buildDir/outputs/apk/somethingAll/debug/*.apk".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions