android-testdpc
android-testdpc copied to clipboard
Build failure with bazel, can't find `build-tools/33.0.0-rc4/lib/dx.jar`
I'm trying to run bazel build testdpc
but it fails.
First it wants SDK 33
, AFAICT we only have Tiramisu
publicly so far. I worked around that by symlinking Tiramisu
to 33
in my SDK install.
After that, it fails with:
INFO: Analyzed target //:testdpc (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/user/.cache/bazel/_bazel_user/1453d0cfa808044da9e372be74772bd0/external/androidsdk/BUILD.bazel:13:25: Extracting interface @androidsdk//:dx_jar_import failed: missing input file 'external/androidsdk/build-tools/33.0.0-rc4/lib/dx.jar', owner: '@androidsdk//:build-tools/33.0.0-rc4/lib/dx.jar'
ERROR: /home/user/.cache/bazel/_bazel_user/1453d0cfa808044da9e372be74772bd0/external/androidsdk/BUILD.bazel:13:25: Extracting interface @androidsdk//:dx_jar_import failed: 1 input file(s) do not exist
Target //:testdpc failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/user/.cache/bazel/_bazel_user/1453d0cfa808044da9e372be74772bd0/external/androidsdk/BUILD.bazel:13:25 Extracting interface @androidsdk//:dx_jar_import failed: 1 input file(s) do not exist
INFO: Elapsed time: 0.412s, Critical Path: 0.32s
INFO: 74 processes: 41 internal, 33 linux-sandbox.
FAILED: Build did NOT complete successfully
If I check the folder, it has a d8.jar
but not dx.jar
Check the command to build "This sample uses the Bazel build system. To build this project, use the "bazel build --noincremental_dexing"
IF you still have an issue on build ....
I had the same issue on my desktops, and recognized it might be an issue on Bazel build itself. Here're the solutions which I googled
- Just copy the dx.jar from old build tool directory to 33 directory
OR
- Use additional command line param to use d8 instead of dx
$ bazel build testdpc --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --nouse_workers_with_dexbuilder
I'm not fully confident with this change, but got a successful build after adding this line on BUILD file (the number of 'dex_shard' was needed to be increased)
android_binary(
name = "testdpc",
custom_package = PACKAGE,
dexopts = [
"--force-jumbo",
],
manifest = MANIFEST,
dex_shards = 2,
multidex = "native",
deps = [
":testdpc_lib",
],
)
$ bazel build testdpc --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --nouse_workers_with_dexbuilder
INFO: Analyzed target //:testdpc (1 packages loaded, 277 targets configured). INFO: Found 1 target... Target //:testdpc up-to-date: bazel-bin/testdpc_deploy.jar bazel-bin/testdpc_unsigned.apk bazel-bin/testdpc.apk INFO: Elapsed time: 7.756s, Critical Path: 7.50s INFO: 13 processes: 4 internal, 8 linux-sandbox, 1 worker. INFO: Build completed successfully, 13 total actions
Thanks, it builds now.
However I noticed that the generated apk does not have a versionCode
or versionName
set.
$ androguard apkid bazel-bin/testdpc.apk
{
"bazel-bin/testdpc.apk": [
"com.afwsamples.testdpc",
null,
""
]
}
Thanks for resolving that! Let's leave this issue open in case other people have this issue - and we'll try to figure out the proper solution which doesn't involve copying files around.
I'm new to using Bazel so don't know the best practices - we're using it to make the build system as consistent as possible with the one used internally for TestDPC development.
Re: the version code not being set - we'll have a fix for that soon.
In my case, changing build tool version to 30.0.3 makes fix it
android_sdk_repository( name = "androidsdk", api_level = 33, build_tools_version = "30.0.3", )
Android build tool 30.0.3 is include dx.jar
I did a write up on how to build TestDPC with Bazel v5.3, that is the latest one available with brew on my macOS machine:
https://pietromaggi.com/2022/11/20/build-testdpc-with-bazel-5.3/
Basel 6 should improve (resolve?) the situation.
This issue should be now fixed with the latest update. Please open a new issue if you find builds errors.