google / bundletool

Bundletool is a command-line tool to manipulate Android App Bundles
https://g.co/androidappbundle
Apache License 2.0
3.52k stars 385 forks source link

Unable to create an APK from an AAB when system locale is Turkish #229

Closed britzl closed 3 years ago

britzl commented 3 years ago

Describe the bug Unable to create a universal APK from an AAB file when system locale is set to Turkish. This is caused by the way bundletool parses the --mode argument value when it tries to match it with one of the accepted Enum values here:

https://github.com/google/bundletool/blob/0.14.0/src/main/java/com/android/tools/build/bundletool/flags/Flag.java#L218

In this case the lowercase string "universal" will be converted to "UNİVERSAL" (note the İ).

Bundletool version(s) affected Version: Tested with 0.14.0 but the code causing the problem has not changed in newer versions.

Stacktrace

Caused by: java.io.IOException: [BT:0.14.0] Error: Not a valid enum value 'universal' of flag --mode. Expected one of: DEFAULT, UNIVERSAL, SYSTEM, SYSTEM_COMPRESSED, PERSISTENT, INSTANT
com.android.tools.build.bundletool.flags.FlagParser$FlagParseException: Not a valid enum value 'universal' of flag --mode. Expected one of: DEFAULT, UNIVERSAL, SYSTEM, SYSTEM_COMPRESSED, PERSISTENT, INSTANT
        at com.android.tools.build.bundletool.flags.Flag$EnumFlag.parse(Flag.java:221)
        at com.android.tools.build.bundletool.flags.Flag$EnumFlag.parse(Flag.java:207)
        at java.base/java.util.Optional.map(Optional.java:265)
        at com.android.tools.build.bundletool.flags.Flag$SingleValueFlag.getValue(Flag.java:177)
        at com.android.tools.build.bundletool.commands.BuildApksCommand.fromFlags(BuildApksCommand.java:467)
        at com.android.tools.build.bundletool.commands.BuildApksCommand.fromFlags(BuildApksCommand.java:445)
        at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:75)
        at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:47)

To Reproduce

  1. Set system locale to Turkish
  2. Run java -jar bundletool-all.jar build-apks --mode universal -- bundle foo.aab --output foo.apk --ks debug.keystore --ks-pass pass:android --ks-key-alias androiddebugkey to generate an apk from an aab file.
  3. Notice "Error: Not a valid enum 'universal' of flag --mode. Expected one of DEFAULT, UNIVERSAL, SYSTEM, SYSTEM_COMPRESSED, PERSISTENT, INSTANT"

Expected behavior The apk should be generated successfully

Known workaround Use a system local that converts "universal" to "UNIVERSAL"

Environment: OS: Windows 10, but should also happen on macOS and Linux.

ymakhno commented 3 years ago

Thank you for the report. Fixed in 1.8.0