-1

I'm trying to install apk file from my PC on my android device and I have a problem. when I erite these code it's all ok

adb install "C:\Users\ntuser\Documents\workspace\Team\apps\_sample\samples\sample_app\build\outputs\apk\app-debug.apk"

but when I'm trying to give relative path it doesn't work

adb install "%~f0\..\..\apps\app_sample\samples\sample_app\build\outputs\apk\app-debug.apk"

I also tried to go into the folder and then install but it alsi did not work

cd %~f0\..\..\apps\app_sample\samples\sample_app\build\outputs\apk\
adb install "app-debug.apk"

Can someone help me please?

STF
  • 1,485
  • 3
  • 19
  • 36
  • Doesn't `%~f0` mean _the full path **and filename** of the batch file_? Perhaps you meant to use `%~dp0` or `%CD%`. – Michael Nov 05 '17 at 13:27
  • @Michael I need the full path **without** the filename of the batch file. – STF Nov 07 '17 at 10:26

3 Answers3

0

As mentioned in the comments, and as long as the SDK tools install directory is already set in %PATH%, you should be able to use any of:

PushD "%~dp0..\..\apps\app_sample\samples\sample_app\build\outputs\apk"
adb install "app-debug.apk"
PopD

PushD "%CD%\..\..\apps\app_sample\samples\sample_app\build\outputs\apk"
adb install "app-debug.apk"
PopD

PushD "%__CD__%..\..\apps\app_sample\samples\sample_app\build\outputs\apk"
adb install "app-debug.apk"
PopD

In these cases, if you don't need to run any other commands you can omit the PopD line and optionally change PushD to CD/D.

If the SDK tools install directory isn't set in %PATH% you will need to use the full path to adb.exe, e.g."%LocalAppData%\Android\sdk\platform-tools\adb.exe" install…

After choosing from above, please make sure that you know the actual location you need because you have provided two different ones in your question:

\apps\_sample\samples\sample_app\build\outputs\apk

\apps\app_sample\samples\sample_app\build\outputs\apk
Compo
  • 36,585
  • 5
  • 27
  • 39
  • Thank you, but it didn't help me - these command give me the home path `C:\Users\ntuser\ ` - but I need the path of the current bat file: `C:\Users\ntuser\Documents\workspace\Team\script\ ` – STF Nov 07 '17 at 09:55
  • The first of those three examples, `%~dp0` will always expand to the full path of the directory holding the running script. If it doesn't you have made a mistake, your system is broken, or you have an anomaly not before discovered. The path has been copied from your question and is assumed that you know that it navigates back two levels before entering the `\apps` tree. – Compo Nov 07 '17 at 10:38
  • maybe `%~dp0` just giving the path of where I'm standing now and not the full path of the file? because I have a `cd %HOMEPATH%` command before this one. – STF Nov 07 '17 at 10:42
  • No, `%CD%` and `%__CD__%` will give you that, _(the current directory)_, but `%~dp0` will always expand to the full path of the directory holding the running script! – Compo Nov 07 '17 at 10:48
  • It can't be. I opened new bat file in this path: "C:\Users\ntuser\Documents\workspace\Team\script\test - Copy.bat" and wrote this commands: `echo %CD% echo %~dp0 echo %__CD__% ` and I got: `C:\Users\ntuser C:\Users\ntuser\ C:\Users\ntuser\ ` – STF Nov 07 '17 at 10:54
  • As I've already stated, `%~dp0` will always expand to the full path of the directory holding the running script, _(even with disabled extensions)_. If that isn't working it suggests an unusual anomaly, a broken/corrupted system or a mistake on your part. There are thousands of scripts and many answers on this forum which confirm this, [here is one](https://stackoverflow.com/questions/5034076/what-does-dp0-mean-and-how-does-it-work) and [here is another](https://stackoverflow.com/questions/112055/what-does-d0-mean-in-a-windows-batch-file). – Compo Nov 07 '17 at 13:17
0

OK, So as far I tried nothing helped me to give a relative path when in the install command.

What I found is that if you want to have a relative path - you need first go to this folder by the cd command and than use relative path in the install command.

The good code:

cd %~f0\..\..\apps\app_sample\samples\sample_app\build\outputs\apk
adb install %CD%\tracking_sample_app-debug.apk

and if you want to return to the home path - you should add:

cd %HOMEPATH%
STF
  • 1,485
  • 3
  • 19
  • 36
0

Now I got a better answer when I asked about something else...

The best command to install app using relative path is adb.exe install and not adb install.

adb.exe install "%~f0\..\..\apps\app_sample\samples\sample_app\build\outputs\apk\sample_app-debug.apk

That's the nicest way doing it!

And thanks to Mofi that gave me this idea in his answer here

STF
  • 1,485
  • 3
  • 19
  • 36