0

[ SOLUTION ]

Thanks to @oguzismail and @stylo I find the solution. In the find command I modified the 2>&1 for 2>/dev/null and deleted the grep command, but I found the problem that it retrieves me two different path (because Android studio it was generation two different apk with the same name in two different paths).

To only get the path of the apk I want, I add a "filter" for my find command so the solution is:

find / -path ./intermediates -prune -o -name app-ipd-debug.apk 2>/dev/null

with name of the folder ./intermediates and -prune -o I can get the path I wanted to.

I saw the solution in this post

[ PROBLEM ]

I am doing a shell script that build an android project, install apk and do some more configurations in the device like set owner device owner (is a kiosk mode app) and some more stuff.

Now I am trying to dynamically build the project and get the apk file to install in the device but it doesn't work correctly.

I try putting the full path as a variable in my shell script and this works installing the app using the command adb install:

adb install -t -r $APK_PATH

I have tried t get the APK_PATH with find command but it retrieves me a lot of output that I don't know how to handle it, the command is :

find / -name apk-file-name.apk

A lot of output with "Permission denied" and "Operation not permitted" is shown and in one line of those the apk path is shown (this is the one I don't know how to get it, only this result)

I try to filter the results using grep but it doesn't work

find / -name apk-file-name.apk 2>&1 | grep -v "Operation not permitted"

and

find / -name apk-file-name.apk 2>&1 | grep -v "Operation not permitted"|"Permission denied"

any help?

Sergio
  • 725
  • 1
  • 7
  • 20
  • Searching `/` for a file is not a good idea at all, I think you should elaborate on *but when I try to get that APK_PATH with terminal, I am not able to do it.* to get a good answer here. If you insist on using find, redirect stderr to /dev/null, like `2>/dev/null` instead of parsing it with grep – oguz ismail Sep 24 '19 at 09:42
  • I am trying your solution and works great, but it retrieves me two different path, one with instant run android studio compilation and another one that it is the one I want to get it. It could be possible to get one of this in specific?. I am not very familiar with shell scripting so it is not easy to me :S – Sergio Sep 24 '19 at 10:08
  • Well, I don't know, maybe you can choose the one you're after by its path?? – oguz ismail Sep 24 '19 at 10:10
  • I find out the solution. Thanks a lot!!@oguzismail – Sergio Sep 24 '19 at 10:32

1 Answers1

1

You can use the locate command to locate files in your file system.

if you haven't enabled it yet, you can do so by running the following command

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

you won't be able to use it for a few minutes since it will index everything and later on you can use locate file_name.apk to find the file you're looking for.

stylo
  • 496
  • 4
  • 12
  • That could be a great solution but I would like to avoid any installation or requirements extra, because this script it will be used to simplify the configuration and installation of an app in multiple devices, so I am trying to avoid anything else than running the script. But thanks a lot! – Sergio Sep 24 '19 at 10:06
  • Gotcha, then I'm guessing you could just send faulty output to `/dev/null` as oguz suggested above – stylo Sep 24 '19 at 10:08
  • I find the solution I looking for. Thanks a lot @stylo – Sergio Sep 24 '19 at 10:33