21

I am trying to build Android on my MacOS, but it gives me this error:

"sed: illegal option -- r"

I tried:

make bootimage
make systemimage
make recovery
brunch
mka bacon

All of them give me the same error.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
flo071
  • 311
  • 1
  • 2
  • 4
  • 9
    If you talk about the classic stream editor `sed` and option `-r` that enables extended regex, then this can be done in MAC with `sed -E`. Is this you talk about or i lost you? – George Vasiliou Apr 29 '17 at 14:17
  • 1
    yes, thats exactly what i meant. but i need to change it in the makefiles of the rom i am compiling. and i cant find wehre the sed -r is used. thank you for your answer. – flo071 Apr 30 '17 at 17:04
  • 4
    Welcome. You can just substitute all instances referring to `sed -r` with `sed -E` since it is the same thing. sed -E will work on mac and all other distros with no problem. – George Vasiliou Apr 30 '17 at 19:25
  • thank you!! but do you know which makefile in the build directory of an android source the sed -r is used? because i cant find it. – flo071 Apr 30 '17 at 23:06
  • Did you try something like `grep -r 'sed -r' /android/dir/*` ? This will scan all the files in a directory for sed -r. Or you can just `grep 'sed -r' file` to search in a particular file – George Vasiliou Apr 30 '17 at 23:12
  • no, i did not ry that. did not know how to do. thank you. – flo071 May 01 '17 at 09:44

2 Answers2

34

Another option is to use homebrew to install gnu-sed:

brew install gnu-sed --with-default-names
Nathan Williams
  • 764
  • 1
  • 6
  • 16
  • 4
    And use `gsed` instead of `sed` - at least in my case on High Sierra – bvj Mar 14 '18 at 03:55
  • 15
    If you want to use `sed` instead of `gsed` the `--with-default-names` option does not work any more. Instead you have to add gnu-sed to the path: `export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"` – dominik May 16 '19 at 11:09
  • 3
    Error: invalid option: --with-default-names – user2707671 Sep 22 '20 at 12:23
  • 4
    `--with-default-names` option [has been removed](https://stackoverflow.com/a/34815955/337194). – Y.H. Dec 17 '20 at 12:39
  • 2
    `ln -s /usr/local/bin/gsed /usr/local/bin/sed` – 0leg Jan 05 '21 at 14:40
5

Editing PATH manually is one way to handle this. However, there is an alternative solution that might work for some.

Most developers these days have conda. conda can install the latest sed and make it visible via $PATH

conda install -c conda-forge sed

conda takes care of editing PATH variable

P.S. Most believe that conda is a package manager for python, but that is not entirely true! I install everything using conda. And it manages environment variables such as PATH really well. https://superuser.com/a/1304148/266871

Thamme Gowda
  • 11,249
  • 5
  • 50
  • 57
  • 2
    This is an interesting way to handle it. However, I would say it's quite a stretch to claim that "most developers these days have `conda`". Can you back up that claim? Even most of the Python devs I work with don't have `conda`... – Jackson Holiday Wheeler Aug 01 '20 at 13:21