Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundletool build-apks --connected-device or --device-spec flag/parameter are not working #9

Closed
saurabhkpatel opened this issue May 21, 2018 · 14 comments

Comments

@saurabhkpatel
Copy link

Describe the bug
I've referred Google IO'18 official session youtube video: https://youtu.be/bViNOUeFuiQ?t=1324 and it says that you can generate the apk set archive for the connected device from the app bundle during testing phase.

I'm trying to run the following command which should generate the apk set for connected device or as per the device-specs. These both commands are not working and giving me the following error.

bundletool build-apks --bundle=app/build/outputs/bundle/debug/bundle.aab --output=my_app.apks --connected-device
bundletool build-apks --bundle=app/build/outputs/bundle/debug/bundle.aab --output=my_app.apks --device-spec=pixel2.json

Bundletool version(s) affected
Version: [e.g. 0.3.3]

Stacktrace
$ bundletool build-apks --bundle=app/build/outputs/bundle/debug/bundle.aab --output=my_app.apks --connected-device

WARNING: The APKs won't be signed and thus not installable unless you also pass a keystore via the flag --ks. See the command help for more information.
[BT:0.3.3] Error: Unrecognized flags: --connected-device
com.android.tools.build.bundletool.utils.flags.ParsedFlags$UnknownFlagsException: Unrecognized flags: --connected-device
at com.android.tools.build.bundletool.utils.flags.ParsedFlags.checkNoUnknownFlags(ParsedFlags.java:90)
at com.android.tools.build.bundletool.commands.BuildApksCommand.fromFlags(BuildApksCommand.java:239)
at com.android.tools.build.bundletool.commands.BuildApksCommand.fromFlags(BuildApksCommand.java:191)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:72)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:44)

$ bundletool build-apks --bundle=app/build/outputs/bundle/debug/bundle.aab --output=my_app.apks --device-spec=pixel2.json

WARNING: The APKs won't be signed and thus not installable unless you also pass a keystore via the flag --ks. See the command help for more information.
[BT:0.3.3] Error: Unrecognized flags: --device-spec
com.android.tools.build.bundletool.utils.flags.ParsedFlags$UnknownFlagsException: Unrecognized flags: --device-spec
at com.android.tools.build.bundletool.utils.flags.ParsedFlags.checkNoUnknownFlags(ParsedFlags.java:90)
at com.android.tools.build.bundletool.commands.BuildApksCommand.fromFlags(BuildApksCommand.java:239)
at com.android.tools.build.bundletool.commands.BuildApksCommand.fromFlags(BuildApksCommand.java:191)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:72)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:44)

To Reproduce
Steps to reproduce the behavior.

  • Use the above-mentioned command to install the application to the connected device.

bundletool build-apks --bundle=app/build/outputs/bundle/debug/bundle.aab --output=my_app.apks --connected-device

Expected behavior
It should generate the apk archive set for the connected device or as per the device spec json file.

Known workaround
Don't know

Environment:
OS: MAC, High Sierra 10.13.4
Device : Pixel2 XL

@plecesne
Copy link
Contributor

plecesne commented May 21, 2018

Thanks for reporting the issue.

These flags eventually couldn't make it in the I/O release, but will be coming shortly.
There is however an easy workaround (at the cost of longer build times): build an APK Set for all devices (i.e. without passing --device-spec or --connected-device), then call "install-apks" with the flag --device-spec or --connected-device.

@saurabhkpatel
Copy link
Author

@plecesne Thanks for the insights and a workaround.

One more question, not sure it will be feature-request or something I don't know.
I want to compare/analyze the two apks: Universal (traditional) apk vs APK to the specific device (for eg. pixel 2 XL). But I didn’t find any way where I can generate apk for a specific device, I can extract the apks as per device configuration but it gives me all different apks. I am looking for a way to generate only one apk which should be for that particular device (for eg: base+en_US+arm64+xxxhdpi = pixel2 XL) Thus, I can compare/analyze that apk.

Any insights on this?

@plecesne
Copy link
Contributor

There is no way today to generate such APK, but more importantly, it is not something that Play would deliver and thus your comparison would not be accurate.
If you just need the list of files, you could just unzip the files from the APKs and look at what's present, but analyzing the resource tables would be more complicated.

@saurabhkpatel
Copy link
Author

I see, so, how google play delivers the apk on the device. If I have pixel 2 XL and google play has 4 different apks (base + en_US + arm64 and xxxhdpi) then google play installs 4 apks on the device?
How merging works here?

Actually, I'm more interested to know about the total apk size for the specific device. So I can conclude that how much apk size has been reduced.

@plecesne
Copy link
Contributor

There is no merging: Play would serve 4 APKs for this app. This is possible with the use of Split APKs. Here is some documentation about Split APKs:

the Android platform is able to treat multiple installed split APKs as a single app

Hence you can just sum the size of the 4 APKs.

@saurabhkpatel
Copy link
Author

@plecesne thanks.
That's it? Is it final to consider the total size of the 4 apks as a benchmark? I thought there must be different size after merging of those 4.

Is it possible to install one by one those 4 apks?

@plecesne
Copy link
Contributor

plecesne commented May 22, 2018 via email

@saurabhkpatel
Copy link
Author

Ok, thanks for the info so far.
Closing this now.

@rksinghj4
Copy link

I am getting following error. Please help.

java -jar bundletool-all-0.4.1.jar get-device-spec --output=motog5.json
[BT:0.4.1] Error: Unable to determine the location of ADB. Please set the --adb flag or define ANDROID_HOME environment variable.
com.android.tools.build.bundletool.exceptions.CommandExecutionException: Unable to determine the location of ADB. Please set the --adb flag or define ANDROID_HOME environment variable.
at com.android.tools.build.bundletool.commands.GetDeviceSpecCommand.lambda$null$1(GetDeviceSpecCommand.java:127)
at java.util.Optional.orElseThrow(Unknown Source)
at com.android.tools.build.bundletool.commands.GetDeviceSpecCommand.lambda$fromFlags$2(GetDeviceSpecCommand.java:125)
at java.util.Optional.orElseGet(Unknown Source)
at com.android.tools.build.bundletool.commands.GetDeviceSpecCommand.fromFlags(GetDeviceSpecCommand.java:120)
at com.android.tools.build.bundletool.commands.GetDeviceSpecCommand.fromFlags(GetDeviceSpecCommand.java:102)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:80)
at com.android.tools.build.bundletool.BundleToolMain.main(BundleToolMain.java:44)

@rksinghj4
Copy link

rksinghj4 commented May 31, 2018

How to pass key to generate install able apks? Please help. I am getting following errors:

java -jar bundletool-all-0.4.1.jar build-apks --bundle F:...\app\build\outputs\bundle\prodMyappRelease\bundle.aab --output=output_apk_archive_set --ks F:...\play-store-release-key.keystore
Error while parsing the flags: Syntax error: flags should start with -- (F:\app\build\outputs\bundle\prodMyappRelease\bundle.aab)

@saurabhkpatel
Copy link
Author

@rksinghj4 For the first error, did you set the ADB path? If not then set it or use the full absolute path of adb.
for the second error, I think there is a problem with --, make sure you've written the correct command. copy-paste sometimes creates the problem.

@rksinghj4
Copy link

Thanks a lot saurabhkpatel. 👍

@agiratech-sankar
Copy link

Hi,
How to resolve this error.
Error: Unable to access jarfile bundletool-all-0.6.0.jar

@plecesne
Copy link
Contributor

plecesne commented Apr 2, 2019

@agiratech-sankar This issue has been closed. Please file a separate issue and fill the form with the details on what you're doing.

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

No branches or pull requests

4 participants