adb not working in powershell but adb.exe works - android

when typing "adb devices" in Powershell, it return a prompt to ask "How do you want to open this file".
However, if I use "adb.exe devices", it works and give me the list of devices.
As I have a lot of scripts written as adb instead of adb.exe, is there a way to fix this?
In cmd, typing adb devices would also work. But the scripts were all PS based. So fixing this in powershell will really helps. Thanks.

As you've confirmed, the problem was an extraneous, empty file literally named adb (without a filename extension) that resided in your C:\WINDOWS\system32 directory.
Since the PATH environment variable (typically) lists C:\WINDOWS\system32 before the directory in which the desired target executable (adb.exe) is located, C:\Program Files (x86)\Intel\Platform\..., PowerShell attempted to execute C:\WINDOWS\system32\adb, which - as an extension-less file - triggered the GUI dialog you saw.
Removing the extraneous C:\WINDOWS\system32\adb file solved your problem.
Get-Command -All adb helped discovered the problem: it listed all forms of a command named adb known to PowerShell, in order of precedence, with information about their type and location; that is, the effective command - the one that is actually invoked - was listed first.
Read on for background information.
As all shells do, if a command uses a mere (file) name (as opposed to a file path), PowerShell looks for executables in the directories listed in the PATH environment variable (accessible as $env:PATH in PowerShell), in order.
That is, if you submit a command line with command name adb, PowerShell - after looking for an internal command by that name first (an alias, function, or cmdlet) - looks for an executable file whose base name is adb, in the directories listed in $env:PATH, and invokes the first one it finds.
On Windows, an executable file is one whose filename extension is listed in the PATHEXT environment variable ($env:PATHEXT); again, the extensions listed there are considered in order. By contrast, on Unix-like platforms it is solely the file mode (the permission bits) that determine whether a file is executable.
However, unlike other shells, PowerShell doesn't just look for executable files in $env:PATH, it considers any file that exactly matches the command name given executable, and in effect passes such a file to the Invoke-Item cmdlet, which triggers the default GUI shell action on the file, equivalent to double-clicking a document in File Explorer on Windows.
This problematic behavior is discussed in this GitHub issue, which proposes that only true executables be considered commands.

Related

.BAT to install apps by dragging them into CMD

I am trying to make a .bat file where it goes to a location and then executes 2 commands.
First one id ADB Devices which works fine but second one ADB install requires the .apk file to work. Now i have something like this
#echo off
cd /d "C:\Users\userDesktop\adb"
adb devices
adb install
#pause
but it gives me
"adb.exe: install requires an argument"
Normally i write ADB install and then drag the file into the window. How do i skip writing ADB install and just dragging the file?
When you start any "bat" or "cmd" (they are virtually equal).
The first external argument is taken internally as parameter %1 However, since that may or may not contain spaces when you drop a file on it (the file.bat or file.cmd) we strip and guarantee "quotes" by using "%~1" which can be passed as an argument to another command.
#echo off
cd /d "C:\Users\user\Desktop\adb"
adb devices
adb install "%~1"
pause
if you wish to ensure it is only an .apk you could modify to enforce .apk by testing the file extension but just as simply filter to enforce .apk by using adb install "%~dpn1.apk" .
Note:- that ~dpn (drive path name) is considered a dirty method of testing, but is a very simple means to not install files that are not .apk (unless you drag a file that also has a similar named companion .apk)
I do not know how adb accepts its arguments, however you should be able to avoid a bat file by selecting adb.exe and making a shortcut for drag and drop usage. That you can then use different ways, such as place in your toolbar or add to your sendTo for right clicking. So it is worth making a shortcut to "....\adb.exe" then modify via properties the command line to include at the end devices & adb.exe install (make sure to add a space before and after), if all is well that should call the "devices" commmand then windows can pass the .apk file name after the " & inst ..."

How to access android root directory

I am developing an application using ionic framework.
The app creates files (*.json) and stores them in /data/user/0/ when i verify whether they exist or not, the result was true which means the files exist in the mentioned directory and I can access and modify their content without problem, but when I check the directory with a file manager or from the computer, no result, the directory is empty.
Could someone tell me what should I do?
use adb to copy the file. Even if it's in root dir, u should have access to it via adb.
Do adb pull data/user/0/filename.json path_on_ur_comp.json.
this will copy the file to the directory you define in the 2nd parameter.
// EDIT:
adb is part of the Android SDK, stands for Android Debug Bridge.
You can use this for MANY MANY different reason but of course, the "main" reason is to debug Android devices. You can use it to transfer files in your case.
In Windows, it's located here:
C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools\adb
In Mac, it's lcoated here:
/Users/USERNAME/Library/Android/sdk/platform-tools/adb
Depending on which OS you use, open that either with Terminal (Mac) or Command Prompt (Windows).
Once you do that, run the following command:
For Mac:
adb pull data/user/0/filename.json /Users/USERNAME/Desktop/somefile.json
For Windows:
adb pull data/user/0/filename.json c:\Users\USERNAME\Desktop\somefile.json
This will copy the file and put it on your desktop

how to edit run.sh file in eclipse

I need to edit run.sh file in eclipse in windows. I'm following instructions in here, and I've installed the Android app completely and it's OK on my Xperia, however when it comes to building the host client part in the fourth line I don't know what run.sh does neither I know how to edit it,by the way, I guess it's a Linux file. And I have to say that I haven't installed CyanogenMod software as it is not Xperia p compatible according to it's website. The code in run.sh file in se.pki.client package, which I downloaded and imported previously, is as following.Althoug I've changed the code in the second line(giving it the path where my jdk is stored) while there's still an error in the first line saying the word "sh" is not correctly spelled and another error in the third line to
#!/bin/sh
JAVA_HOME=C:\ProgramFiles\java\jdk1.7.0\
$JAVA_HOME/bin/java -Dsun.security.smartcardio.library=/usr/local/lib/libpcsclite.so -cp bin/ org.nick.sepkiclient.Main $*
.sh files are the linux equivalent to a batch file. From the code you posted it just runs the java command (giving it a bunch of command line inputs) you should be able to run the same command in the windows terminal by just replacing the paths to windows paths. If there is more to the script than the 3 lines, you're going to needed to try and convert each line to a valid windows command (depending on the complexity of the script, this may not be possible.)
Your other option is to install software like Cygwin which adds a POSIX compliment shell (along with many other linux-ish modifications). This should allow you to run .sh files 'natively' in windows (it will require some fiddling with the script to provide the correct paths). Be sure you read about cigwin before you install it, it changes quite a lot about your system that you might not be comfortable with.
Each option has its drawbacks, and both require a little knowledge of shell scripting. Might just be easier to run Linux for what your doing (it behaves itself reasonably well in a VM).
Make sure you have it set as a unix file.
Window> Preferences>General>Workspace
Select line delimiter Other then Unix and test file encoding as UTF-8
As a last resort run dos2unix on the file from the shell.

How to navigate to adb exe using command prompt in windows 7

I am trying to familiarise myself with using adb from the command prompt.
My adb.exe is installed at:
C:\Program Files(x86)\Android\android-sdk\platform-tools
I have tried starting off by typing in cd:C\ to take me to the C drive
Then I have typed in the path quoted above, sometimes putting Program Files(x86) in quote marks,
other times inserting % in between Program and Files.
But always I get the same answer - "The system cannot find the path specified".
Even when I type the path and then put in “adb devices” I get nothing.
I have tried inserting each of the following in the path in system variables as follows:
;C:\"Program Files(x86)"\Android\android-sdk\platform-tools\
C:\"Program Files(x86)"\Android\android-sdk\platform-tools\
;C:\Program Files(x86)\Android\android-sdk\platform-tools
And then typing “adb devices”.
The message is the same – “adb is not recognised as an internal or external command, operable program or batch command.
You can call adb directly from the directory you are currently in: "C:\Program Files(x86)\Android\android-sdk\platform-tools\adb.exe" (With quotes!) You can also navigate to the platform-tools directory and then call adb.exe, use cd .. to go to a directory level up, you can hit TAB to let windows list the appropriate directories, this works also if one or more characters are entered.
Btw, just added "C:\Program Files\Android\android-sdk\platform-tools" to my PATH and it works just fine! Separate the entires with a semicolon.
for using a 64 bit os try going step by step,
type in command prompt
cd "C:\Program Files (x86)"
you will enter C:\Program Files (x86)directory
then type
cd Android\android-sdk\platform-tools
It's the spaces that are messing people up. Windows users need to remember one important thing when dealing with command lines: do not install the utilities to folders where there's a space in the folder name - it will save you a lot of hassle which sometimes can't even be solved by using quotes.
For example, I've installed the Android SDK to C:\Android\android-sdk-windows
To open a command prompt, I have a shortcut to ("target") C:\Windows\System32\cmd.exe
And the "Start in" path is C:\Android\android-sdk-windows\platform-tools
now all I do is double-click the shortcut and I can dive right in to ADB

Cannot use ndk-build on Cygwin

I have to use NDK for a clien't project. I am using Windows 7.
I followed the installation instructions. I have installed Cygwin 1.7.1.
In Cygwin bash, I go into the android NDK root directory.
When I see the contents of the directory, usin $dir command, I can see all the contents including ndk-build, but when I try to use ndk-build, this is the result I get:
$ndk-build
bash: ndk-build: command not found.
Not sure what I am doing wrong.
Cygwin emulates a GNU/Linux environment on your Windows computer. This means you're working with a "Shell" which is not exactly the same as the Windows command-line.
If you type asdf.exe in your Windows command-line, it tries to find asdf.exe in the current directory. If it can find it, the file is executed. If it can't find it, it'll go through every directory of your %PATH% and try again.
However, if you type asdf in your bash (there are multiple kind of shells, the Bourne Again SHell is one of them), it will not look after it in the current directory. Instead it'll try to find it in one of your PATH directories. Can't give you any sources here, but AFAIK it's for security reasons. If you want to run a file which is not in your PATH, you must prepend it with its absolute of relative path. You can use ./, it points to the current directory.
That's why you need to type ./ndk-build, because it's in the current directory and not your path. Something like /path/to/ndk/ndk-build will also work, but you have to type a bit more :).
(In fact it's even more complicated, if you want to execute a file, you need execute permissions for it. Google will help you if you have any problems with that.)

Categories

Resources