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

mobile-install is failing on a python import error #12741

Closed
veganafro opened this issue Dec 21, 2020 · 16 comments
Closed

mobile-install is failing on a python import error #12741

veganafro opened this issue Dec 21, 2020 · 16 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: bug

Comments

@veganafro
Copy link

Description of the problem / feature request:

I'm attempting to run bazel mobile-install for an android_binary target. The app is the simple hello world app generated by the single activity app base in Android Studio.

This is the incorrect output I'm seeing:

$ bazel mobile-install //app/src:app_binary --start_app --incremental

INFO: Analyzed target //app/src:app_binary (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Users/jeremymuhia/development/mono/android/app/src/BUILD:5:15: Installing //app/src:app_binary incrementally failed (Exit 1): incremental_install failed: error executing command bazel-out/darwin-py2-opt-exec-2B5CBBC6/bin/external/bazel_tools/tools/android/incremental_install --output_marker bazel-out/darwin-fastbuild/bin/app/src/app_binary_files/incremental_deploy_marker ... (remaining 10 argument(s) skipped)
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_jeremymuhia/f9dfbeb00953a93e3d2ab5498ee6f23d/execroot/__main__/bazel-out/darwin-py2-opt-exec-2B5CBBC6/bin/external/bazel_tools/tools/android/incremental_install.runfiles/bazel_tools/tools/android/incremental_install.py", line 25, in <module>
    from concurrent import futures
ImportError: No module named concurrent
Target //app/src:app_binary failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.270s, Critical Path: 0.11s
INFO: 3 processes: 3 internal.
FAILED: Build did NOT complete successfully

This seems peculiar because when I build an apk with bazel build //app/src:app_binary and install it manually with adb install bazel-bin/app/src/app_binary.apk, I can see that the app is installed on the device and is without any runtime errors.

Feature requests: what underlying problem are you trying to solve with this feature?

mobile-install does not seem to be working correctly. The incremental_install.py file seems to depend on a concurrent module/file that can't be pip installed and doesn't seem to be packaged with Bazel.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

This repo contains the source code for the template Android app. Cloning, navigating to the android directory, and executing bazel mobile-install //app/src:app_binary --start_app --incremental should reproduce the error.

What operating system are you running Bazel on?

macOS Catalina version 10.15.6

What's the output of bazel info release?

release 3.7.2-homebrew

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

https://github.com/veganafro/mono.git
cefc78574a063a945098b01b70f4de5c385717ea
cefc78574a063a945098b01b70f4de5c385717ea
@aiuto aiuto added team-Android Issues for Android team untriaged labels Jan 6, 2021
@rockwotj
Copy link
Contributor

I believe this will be fixed in the next bazel release.

@joprice
Copy link

joprice commented Jan 19, 2021

I worked around this using rules_nixpkgs and rules_python:

WORKSPACE

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_cc_configure", "nixpkgs_git_repository", "nixpkgs_package")

nixpkgs_package(
      name = "python37",
      repositories = {"nixpkgs": "@nixpkgs//:default.nix"},
  )

nixpkgs_package(
      name = "python27",
      nix_file = "//:python27.nix",
      repositories = {"nixpkgs": "@nixpkgs//:default.nix"},
)

register_toolchains("//:my_py_toolchain")

python27.nix

{pkgs ? import <nixpkgs> {}}:
  {
    python27 = (pkgs.python2.withPackages (packages: [packages.futures]));
  }

BUILD

py_runtime(
      name = "python2_runtime",
      interpreter = "@python27//:bin/python",
      python_version = "PY2",
      visibility = ["//visibility:public"],
  )

py_runtime(
      name = "python3_runtime",
      interpreter = "@python37//:bin/python",
      python_version = "PY3",
      visibility = ["//visibility:public"],
)

py_runtime_pair(
      name = "my_py_runtime_pair",
      py2_runtime = ":python2_runtime",
      py3_runtime = ":python3_runtime",
)

toolchain(
      name = "my_py_toolchain",
      toolchain = ":my_py_runtime_pair",
      toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)

Since I was already using rules nix, this was also an easy way to lock down the python version, and provide whatever extra packages I need.

@khushmanvar
Copy link

@veganafro , that is because you might be using python3 and bazel uses python2, even I had the same problem, so this is how I figure it out,

  1. install pip2 (pacakge manager for python2) on your device
  2. then run pip2 install concurrent

@jimmyhoran
Copy link

jimmyhoran commented Mar 2, 2021

Duplicate issue over at bazelbuild/rules_android bazelbuild/rules_android#32

@jimmyhoran
Copy link

jimmyhoran commented Mar 2, 2021

@veganafro , that is because you might be using python3 and bazel uses python2, even I had the same problem, so this is how I figure it out,

  1. install pip2 (pacakge manager for python2) on your device
  2. then run pip2 install concurrent

No longer a viable option moving forward with the latest version of pip dropping support for Python 2.7 🙈

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.

Also, I believe Bazel currently has mixed support for python2 and python3, with a lot of work already done to support a python3 toolchain. It also looks like there's some work underway to complete the move to Python3 with the following PR #11201.

@jimmyhoran
Copy link

I believe this will be fixed in the next bazel release.

@rockwotj is there a merged pull request/closed issue we can track to see if this has already been resolved or not?

@KanzaSheikh
Copy link

Has this issue been solved? The mobile-install is still throwing error for the concurrent module. How can I run my app?

@Monibsediqi
Copy link

Has this issue been solved? I still face this issue
Traceback (most recent call last):
File "/private/var/tmp/_bazel_monibsediqi/66f39706e456471fddd5fbdd43dea70d/execroot/main/bazel-out/darwin-py2-opt-exec-2B5CBBC6/bin/external/bazel_tools/tools/android/incremental_install.runfiles/bazel_tools/tools/android/incremental_install.py", line 25, in
from concurrent import futures
ImportError: No module named concurrent

@ahumesky
Copy link
Contributor

The tool that's crashing has been migrated to python3, so first check if installing python3 solves the issue if you don't already have it installed.

@Monibsediqi
Copy link

Thanks for the prompt response. The problem is solved

@KanzaSheikh
Copy link

@Monibsediqi sir, may I ask how you solved the issue?

@Monibsediqi
Copy link

Monibsediqi commented May 13, 2021

@KanzaSheikh, I don't remember well but I guess the problem was with python. I had installed python using anaconda. So I reinstalled it using pip. I guess that solved my problem at that moment. Then, I had to track down a series of other issues that I forgot how this one was solved. Hope it helps

@KanzaSheikh
Copy link

@Monibsediqi Thanks for answering! I'll try this out

@jadtl
Copy link

jadtl commented May 29, 2021

On macOS Big Sur I managed to fix the issue by running pip install futures

@ahumesky ahumesky added P2 We'll consider working on this in future. (Assignee optional) type: bug and removed untriaged labels Jun 18, 2021
@vple
Copy link

vple commented Aug 8, 2021

I also have this issue. I've tried various combinations of workarounds in this thread, but none of them have worked for me. Specifying a python toolchain (via my pyenv versions or via nix) seemed to get the closest, though I then started seeing some queue import issue.

I did find a different workaround. I don't quite follow how/why toolchains are related to this issue, but this approach currently seems to be working for me.

bazel mobile-install :app --incompatible_use_python_toolchains=false

@sgowroji
Copy link
Member

sgowroji commented Jul 13, 2022

We are closing this issue as we can see it is resolved from the above workaround comments #1 #2 #3 #4. Please reach us back if the issue still persists or reopen a new issue by adding the above as reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: bug
Projects
None yet
Development

No branches or pull requests