how to edit run.sh file in eclipse - android

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.

Related

adb not working in powershell but adb.exe works

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.

What is the Android equivalent of /tmp and how do I get Python scripts to use it?

I am trying to use pelican (python) on Android (in termux). It fails when pelican tries to write to /tmp which near as I can tell, does not exist, and/or is a read-only file system.
The error is from os.py, in makedirs(name, mode)
OSError: [Errno 30] Read-only file system: '/tmp'
How do I tell any sort of script on Android to use a different location for /tmp?
How do I tell python on Android (in Termux) to use a different location for /tmp?
What is the Android equivalent of /tmp?
Editing to respond to suggestion this is a duplicate:
I found that answer helpful, but it doesn't pertain to this question.
I tried the instructions suggested here: https://stackoverflow.com/a/18280309/608970 and found that by setting TMP, TMPDIR and TEMP that I can indeed change /tmp for python and create tmp files, IF the script uses the tempfile module.
Apparently, pelican does not. Which leaves my original question, in Android what is the model for /tmp, how do we port arbitrary scripts, and does it require a change to the code, or can it be otherwise fixed by changing the Android environment the code works within?
According to https://stackoverflow.com/a/41105574/493161, it's /data/local/tmp, but my experience with termux is that it cannot read many/most files and directories that can be seen using adb from the desktop, and has write access to nothing (that I've found) outside its own files. I'd suggest mkdir $HOME/tmp instead, and using that.
Some of the other answers on that same question have good information on the lack of /tmp. Note that /data/local/tmp does not have the sticky ("t") bit set, nor does it have full read/write access to all users, as does Linux.
A better answer for many use cases is to use the file sharing options built into termux, documented at https://wiki.termux.com/wiki/Sharing_Data
$ termux-setup-storage
$ cp test.png ~/storage/downloads
$ xdg-open ~/storage/downloads/test.png

Android Terminal-IDE: terminal-gcc error: arm-eabi-gcc not found

I'm using Terminal-IDE as my development environment. (Google code site here.)
I'm running Terminal-IDE v 2.02 - the very latest. My Android versions are:
Android 4.0.3
Software version 2.14.531.3 71ORD
(the rest aren't likely pertinent, but more on request)
I'm in a suitable development directory with a simple enough c source code file ready and run 'make'.
I have never yet gotten any compilation to work successfully. Most likely, there's a version mis-match with regard to what executable is available versus what the software is looking for.
Here's the command and error message:
terminal-gcc -c -Wall -I/data/data/com.spartacusrex.spartacuside/files/local/include tester.c -o tester.o
/data/data/com.spartacusrex.spartacuside/files/system/bin/terminal-gcc[43]: arm-eabi-gcc: not found
make: *** [tester.o] Error 127
Snafu, of course. I'm not at all sure how to find out what the right compiler file name(s) should be because, on this non-rooted phone, I don't have permissions to hunt through the PATH and find the actual executables.
It may also be that PATH is set wrong. All input appreciated.
...I'm not sure what's supposed to happen, but I found in the Terminal-IDE directory tree the file:
$IDESYSTEM/android-gcc-4.4.0.tar.gz
I also found that terminal-gcc is a bash script. Looking inside it seemed to say that a gcc tree should exist in "$HOME", which is the installation directory. So, I unzipped, then un-tarred the file identified above and put the resulting directory tree as a top-level subdirectory.
Well well, what do you know? Success.
I went a little further and created soft links to the actual compiler in ~/bin for both gcc and just cc, and suddenly all my previously created "Makefile" scripts used in other projects I wanted to move over started working perfectly.
Apparently, even though I thought I'd done it right, I overlooked running this script:
./system/bin/install_gcc
It extracts the tar, like I did, but does not create the links you may need.
Hey, if you're glad I got here before you, give it a thumbs up!
A credit goes to #Richard T for his enthusiasm regarding Terminal IDE. The answer is intended to enumerate the steps needed for running a C code.
To run a C code
Run Terminal IDE and extract the gcc package by executing
install_gcc
Create a directory for your projects within the Terminal IDE directory tree. Then in the directory create a source .c file with some code (filename.c here). Compile it
terminal-gcc -c filename.c
Create the executable file
terminal-gcc filename.o -o filename.out
Run the output file
./filename.out
If you'd like to use the PC (laptop) keyboard you can telnet Terminal IDE.
To Telnet Terminal IDE
From Terminal IDE start the telnetd deamon by executing
telnetd
Connect the Android device to the PC (laptop) and type
adb forward tcp:[port] tcp:8080
telnet 127.0.0.1 [port]
P.S. Telnet's default port is 23.

How to open .bashrc in Cygwin

When I try to compile my Android NDK program, it shows the following error:
Program "${SA}\android-ndk-r8\ndk-build.cmd" not found in PATH
(the value of the environment variable "SA" is C:)
I am using Cygwin on Windows 7. How do I open my .bashrc file? I read that I need to add the following lines to my .bashrc to fix the problem:
NDK_HOME=/opt/android-ndk-r8
export NDK_HOME
But I am not sure how to open .bashrc and edit the file as I have never done this before.
There are a number of text editors available under Cygwin, either installed by default or installable by using setup.exe.
vi/vim is probably the most common. It has a bit of a learning curve. Run vimtutor from your command line for a tutorial.
If you're very ambitious, you can try emacs. Run emacs from the command prompt, then Control-H t to run the built-in tutorial.
nano is a simpler and more user-friendly editor. It shows the most common commands at the bottom of the screen, including a help command. It may be the best one to start with.
You can use Windows editors like Notepad or Wordpad, but they're likely to add Windows-style end-of-line markers to any files you edit. You can use the dos2unix command (man dos2unix for more information) to fix that up, but IMHO that's more trouble than it's worth unless you really like Windows editors more than Unix-style editors.
The echo command in Henry's answer is a quick-and-dirty way to add a single line to a file. If you want to do anything more complex (say, deleting or changing lines, or adding lines other than at the very end), you'll need a real editor. To edit your .bashrc:
nano ~/.bashrc
(or use another editor of your choice).
You can do
echo "NDK_HOME=/opt/android-ndk-r8 export NDK_HOME" >> ~/.bashrc
be sure to restart your cygwin window afterwards

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