user1209216
user1209216

Reputation: 7984

Bazel - unable to build with Android Studio

First, I installed and configured Bazel, now I am able to succesfully compile and deploy app, using that tutorial.

However, I'm stuck with Android Studio. I installed official Bazel plugin, then tried to import my Bazel project to Android studio (import from BUILD file). And I'm getting sync errors:

Syncing project: Sync (incremental)... Updating VCS... Running Bazel info... Command: bazel info --tool_tag=ijwb:AndroidStudio --curses=no --color=yes --progress_in_terminal_title=no --

Computing VCS working set... Querying targets in project directories... Command: bazel query --tool_tag=ijwb:AndroidStudio --output=label_kind --keep_going "attr(\"tags\", \"^((?!manual).)*$\", //src/main/...:all)" --

2 targets found under project directories; syncing 2 of them. Sync targets from project view directories:
//src/main/java/com/example/bazel:greeter_activity //src/main:app

Building Bazel targets... Command: bazel build --tool_tag=ijwb:AndroidStudio --keep_going --build_event_binary_file=/tmp/intellij-bep-782d8b0b-2f34-43f6-8f09-1efdd034cbfb --nobuild_event_binary_file_path_conversion --curses=no --color=yes --progress_in_terminal_title=no --aspects=@intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect --override_repository=intellij_aspect=/home/michal/.AndroidStudio3.5/config/plugins/aswb/aspect --output_groups=intellij-info-android,intellij-info-generic,intellij-info-java,intellij-resolve-android,intellij-resolve-java -- //src/main/java/com/example/bazel:greeter_activity //src/main:app

Loading: Loading: 0 packages loaded Analyzing: 2 targets (0 packages loaded, 0 targets configured) Analyzing: 2 targets (31 packages loaded, 622 targets configured) ERROR: /home/michal/AndroidStudioProjects/bazel/2/examples-master/android/tutorial/src/main/java/com/example/bazel/BUILD:5:1: in @intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect aspect on android_library rule //src/main/java/com/example/bazel:greeter_activity: Traceback (most recent call last): File "/home/michal/AndroidStudioProjects/bazel/2/examples-master/android/tutorial/src/main/java/com/example/bazel/BUILD", line 5 @intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect(...) File "/home/michal/.cache/bazel/_bazel_michal/d2759e71c9e0462cf95e741761af2e78/external/intellij_aspect/intellij_info_bundled.bzl", line 54, in _aspect_impl intellij_info_aspect_impl(target, ctx, semantics) File "/home/michal/.cache/bazel/_bazel_michal/d2759e71c9e0462cf95e741761af2e78/external/intellij_aspect/intellij_info_impl.bzl", line 895, in intellij_info_aspect_impl collect_android_info(target, ctx, semantics, ide_info, <2 more arguments>) File "/home/michal/.cache/bazel/_bazel_michal/d2759e71c9e0462cf95e741761af2e78/external/intellij_aspect/intellij_info_impl.bzl", line 706, in collect_android_info get_res_artifacts(ctx.rule.attr.resource_files, andr...) File "/home/michal/.cache/bazel/_bazel_michal/d2759e71c9e0462cf95e741761af2e78/external/intellij_aspect/intellij_info_impl.bzl", line 118, in get_res_artifacts for file in resource.files: ... type 'depset' is not iterable. Use the to_list() method to get a list. Use --incompatible_depset_is_not_iterable=false to temporarily disable this check. INFO: Analyzed 2 targets (33 packages loaded, 699 targets configured). INFO: Found 2 targets... INFO: Deleting stale sandbox base /home/michal/.cache/bazel/_bazel_michal/d2759e71c9e0462cf95e741761af2e78/sandbox [0 / 1] [Prepa] BazelWorkspaceStatusAction stable-status.txt ERROR: command succeeded, but not all targets were analyzed INFO: Elapsed time: 3.012s, Critical Path: 0.02s INFO: 0 processes. FAILED: Build did NOT complete successfully FAILED: Build did NOT complete successfully INFO: Build Event Protocol files produced successfully. FAILED: Build did NOT complete successfully build invocation result: build_error Sync was successful, but there were Bazel build errors. The project may not be fully updated or resolve until fixed. If the errors are from your working set, please uncheck 'Bazel > Sync > Expand Sync to Working Set' and try again. Parsing build outputs... Total rules: 0, new/changed: 0, removed: 0 Reading IDE info result... Updating target map Loaded 0 aspect files, total size 0kB Target map size: 0 Reading jdeps files... Loaded 0 jdeps files, total size 0kB Reading package manifests... Java content entry count: 1 Updating Unpacked AAR libraries... Updating Jar Cache... Prefetching files... Refreshing files Computing directory structure... Committing project structure... Workspace has 0 libraries Android resource module count: 0, run config modules: 0, order entries: 0, generated resources: 0 Workspace has 2 modules Updating in-memory state... Could not read from manifest file: /home/michal/AndroidStudioProjects/bazel/2/examples-master/android/tutorial/AndroidManifest.xml Sync finished

Error:(5, 1) in @intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect aspect on android_library rule //src/main/java/com/example/bazel:greeter_activity:

Upvotes: 5

Views: 3170

Answers (2)

SG_Bazel
SG_Bazel

Reputation: 355

You need to clean by `bazel clean --expunge`. It will remove all downloaded artifacts. You should clean and rebuild by below steps. 
  1. Please uncheck 'Bazel > Sync > Expand Sync to Working Set' and try again.
  2. Build through bazel plugin from intellij

Upvotes: 0

Jin
Jin

Reputation: 13553

The pile of error messages here is hard to read, but here's the root cause:

"/home/michal/.cache/bazel/_bazel_michal/d2759e71c9e0462cf95e741761af2e78/external/intellij_aspect/intellij_info_impl.bzl", line 118, in get_res_artifacts for file in resource.files: ... type 'depset' is not iterable. Use the to_list() method to get a list. Use --incompatible_depset_is_not_iterable=false to temporarily disable this check.

Either add build --incompatible_depset_is_not_iterable=false to your project's .bazelrc file, or wait for the next plugin release v2019.09.16 that contains the patch fix.

Upvotes: 0

Related Questions