I have python working on ADB from the command line, I wasn't happy about having to develop with that little virtual keyboard so I made some changes and wrote a short shell script to launch python after setting up some variables.
What I did exactly:
1) I created a blank.img file on my pc and formated it to ext2 as if I was making a chroot image for ubuntu but instead I left it blank. I then named it apps.img but that doesn't matter.
2) I pushed it to my phone ( 4 gigs just for fun)
3) I mounted it via Terminal Emulator on my phone, had to use bash to get the syntax I used on the pc to work with "mount -o loop " . created a folder in /mnt called "myside" so "/mnt/myside" and mounted into "/mnt/myside"
4) I copied all the files, libs, execs, etc into/onto the img file
5) I put my script in "/system/bin" , named it "python" and made it executable, so "/system/bin/python"
6) I tested via "adb shell"
Code:
[email protected]:~$ adb shell
[email protected]:/ $ su
[email protected]:/ # python
Python 2.7.2 (default, Jun 3 2013, 20:01:13)
[GCC 4.4.3] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import os
>>> import math
>>> import io
ANDROID_PRIVATE = /mnt/myside/com.hipipal.qpyplus0/files
>>> import android
>>> import twisted
>>> import PIL
>>> print(os.environ)
{'EXTERNAL_STORAGE': '/storage/emulated/legacy', 'LOOP_MOUNTPOINT': '/mnt/obb', 'BOOTCLASSPATH': '/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar', 'ANDROID_PROPERTY_WORKSPACE': '8,49152', 'USER': 'shell', 'PATH': '/mnt/myside/com.hipipal.qpyplus0/files/bin:/mnt/myside/com.hipipal.qpyplus2/scripts/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin', 'HOME': '/', 'ANDROID_STORAGE': '/storage', 'LD_LIBRARY_PATH': '/mnt/myside/com.hipipal.qpyplus2/lib:/vendor/lib:/system/lib', 'EMULATED_STORAGE_TARGET': '/storage/emulated', 'SHELL': '/system/bin/sh', 'ANDROID_ASSETS': '/system/app', 'ANDROID_BOOTLOGO': '1', '_': '/mnt/myside/com.hipipal.qpyplus0/files/bin/python', 'TERMINFO': '/system/etc/terminfo', 'MKSH': '/system/bin/sh', 'PYTHONOPTIMIZE': '2', 'ANDROID_PRIVATE': '/mnt/myside/com.hipipal.qpyplus0/files', 'ANDROID_SOCKET_adbd': '9', 'SECONDARY_STORAGE': '/storage/sdcard1', 'PYTHONPATH': '/mnt/myside/com.hipipal.qpyplus2/lib/site-packages:/mnt/myside/com.hipipal.qpyplus0/files/lib/site-packages:/mnt/myside/com.hipipal.qpyplus0/files/lib/lib-dynload:/mnt/myside/com.hipipal.qpyplus0/files/lib/config:/mnt/myside/com.hipipal.qpyplus0/files/lib/python27:/mnt/myside/com.hipipal.qpyplus0/files/lib/QPython', 'RANDOM': '29772', 'ANDROID_DATA': '/data', 'TERM': 'linux', 'EMULATED_STORAGE_SOURCE': '/mnt/shell/emulated', 'TMPDIR': '/mnt/myside/com.hipipal.qpyplus2/cache', 'HOSTNAME': 'android', 'ANDROID_ROOT': '/system', 'PYTHONHOME': '/mnt/myside/com.hipipal.qpyplus0/files:/mnt/myside/com.hipipal.qpyplus0/files/bin/python', 'ASEC_MOUNTPOINT': '/mnt/asec', 'ANDROID_CACHE': '/cache'}
>>> dir(PIL)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
>>> dir(twisted)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_version', 'python', 'version']
>>> from PIL import image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name image
>>> dir(android)
['AndroidBrowser', 'AndroidService', 'BuildInfo', 'KEYCODE_0', 'KEYCODE_1', 'KEYCODE_2', 'KEYCODE_3', 'KEYCODE_4', 'KEYCODE_5', 'KEYCODE_6', 'KEYCODE_7', 'KEYCODE_8', 'KEYCODE_9', 'KEYCODE_A', 'KEYCODE_ALT_LEFT', 'KEYCODE_ALT_RIGHT', 'KEYCODE_APOSTROPHE', 'KEYCODE_AT', 'KEYCODE_B', 'KEYCODE_BACK', 'KEYCODE_BACKSLASH', 'KEYCODE_C', 'KEYCODE_CALL', 'KEYCODE_CAMERA', 'KEYCODE_CLEAR', 'KEYCODE_COMMA', 'KEYCODE_D', 'KEYCODE_DEL', 'KEYCODE_DPAD_CENTER', 'KEYCODE_DPAD_DOWN', 'KEYCODE_DPAD_LEFT', 'KEYCODE_DPAD_RIGHT', 'KEYCODE_DPAD_UP', 'KEYCODE_E', 'KEYCODE_ENDCALL', 'KEYCODE_ENTER', 'KEYCODE_ENVELOPE', 'KEYCODE_EQUALS', 'KEYCODE_EXPLORER', 'KEYCODE_F', 'KEYCODE_FOCUS', 'KEYCODE_G', 'KEYCODE_GRAVE', 'KEYCODE_H', 'KEYCODE_HEADSETHOOK', 'KEYCODE_HOME', 'KEYCODE_I', 'KEYCODE_J', 'KEYCODE_K', 'KEYCODE_L', 'KEYCODE_LEFT_BRACKET', 'KEYCODE_M', 'KEYCODE_MEDIA_FAST_FORWARD', 'KEYCODE_MEDIA_NEXT', 'KEYCODE_MEDIA_PLAY_PAUSE', 'KEYCODE_MEDIA_PREVIOUS', 'KEYCODE_MEDIA_REWIND', 'KEYCODE_MEDIA_STOP', 'KEYCODE_MENU', 'KEYCODE_MINUS', 'KEYCODE_MUTE', 'KEYCODE_N', 'KEYCODE_NOTIFICATION', 'KEYCODE_NUM', 'KEYCODE_O', 'KEYCODE_P', 'KEYCODE_PERIOD', 'KEYCODE_PLUS', 'KEYCODE_POUND', 'KEYCODE_POWER', 'KEYCODE_Q', 'KEYCODE_R', 'KEYCODE_RIGHT_BRACKET', 'KEYCODE_S', 'KEYCODE_SEARCH', 'KEYCODE_SEMICOLON', 'KEYCODE_SHIFT_LEFT', 'KEYCODE_SHIFT_RIGHT', 'KEYCODE_SLASH', 'KEYCODE_SOFT_LEFT', 'KEYCODE_SOFT_RIGHT', 'KEYCODE_SPACE', 'KEYCODE_STAR', 'KEYCODE_SYM', 'KEYCODE_T', 'KEYCODE_TAB', 'KEYCODE_U', 'KEYCODE_UNKNOWN', 'KEYCODE_V', 'KEYCODE_VOLUME_DOWN', 'KEYCODE_VOLUME_UP', 'KEYCODE_W', 'KEYCODE_X', 'KEYCODE_Y', 'KEYCODE_Z', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__test__', 'accelerometer_enable', 'accelerometer_enabled', 'accelerometer_reading', 'ack_stop', 'action_send', 'check_pause', 'check_stop', 'get_buildinfo', 'get_dpi', 'hide_keyboard', 'init', 'map_key', 'open_url', 'show_keyboard', 'start_service', 'stop_service', 'vibrate', 'wait_for_resume', 'webbrowser', 'wifi_scan', 'wifi_scanner_enable']
>>> help(twisted)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'help' is not defined
>>> help(os)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'help' is not defined
>>>
[email protected]:/ # set
ANDROID_ASSETS=/system/app
ANDROID_BOOTLOGO=1
ANDROID_CACHE=/cache
ANDROID_DATA=/data
ANDROID_PROPERTY_WORKSPACE=8,49152
ANDROID_ROOT=/system
ANDROID_SOCKET_adbd=9
ANDROID_STORAGE=/storage
ASEC_MOUNTPOINT=/mnt/asec
BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar
COLUMNS=80
EMULATED_STORAGE_SOURCE=/mnt/shell/emulated
EMULATED_STORAGE_TARGET=/storage/emulated
EXTERNAL_STORAGE=/storage/emulated/legacy
HOME=/
HOSTNAME=android
IFS='
'
KSHEGID=0
KSHGID=0
KSHUID=0
KSH_VERSION='@(#)MIRBSD KSH R40 2011/10/07'
LD_LIBRARY_PATH=/vendor/lib:/system/lib
LINES=24
LOOP_MOUNTPOINT=/mnt/obb
MKSH=/system/bin/sh
OPTIND=1
PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
PGRP=4849
PIPESTATUS[0]=0
PPID=4844
PS1='$(precmd)[email protected]$HOSTNAME:${PWD:-?} # '
PS2='> '
PS3='#? '
PS4='+ '
PWD=/
RANDOM=5114
SECONDARY_STORAGE=/storage/sdcard1
SECONDS=289
SHELL=/system/bin/sh
TERM=linux
TERMINFO=/system/etc/terminfo
TMOUT=0
USER=shell
USER_ID=0
_=set
[email protected]:/ #
And this is the script that I used to launch it...
Code:
#!/system/bin/sh
export ANDROID_PRIVATE="/mnt/myside/com.hipipal.qpyplus0/files"
export LD_LIBRARY_PATH="/mnt/myside/com.hipipal.qpyplus2/lib:$LD_LIBRARY_PATH"
export PATH="/mnt/myside/com.hipipal.qpyplus0/files/bin:/mnt/myside/com.hipipal.qpyplus2/scripts$PATH"
export PYTHONHOME="/mnt/myside/com.hipipal.qpyplus0/files:/mnt/myside/com.hipipal.qpyplus0/files/bin/python"
export PYTHONOPTIMIZE="2"
export PYTHONPATH="/mnt/myside/com.hipipal.qpyplus2/lib/site-packages:/mnt/myside/com.hipipal.qpyplus0/files/lib/site-packages:/mnt/myside/com.hipipal.qpyplus0/files/lib/lib-dynload:/mnt/myside/com.hipipal.qpyplus0/files/lib/config:/mnt/myside/com.hipipal.qpyplus0/files/lib/python27:/mnt/myside/com.hipipal.qpyplus0/files/lib/QPython"
export TMPDIR="/mnt/myside/com.hipipal.qpyplus2/cache"
/mnt/myside/com.hipipal.qpyplus0/files/bin/python
I was just gonna add the variables to my "mkshrc" file but I found problems with that chroot'ing into linux, I guess its best for now to set it up in a script that way it doesn't effect the global system so to speak, I just hope that if another program or script calles python it will work like normal ( i.e. set up the variables and launch python, or run said script in /system/bin called python)
What do you think I am missing?
I am almost certain that the normal program that does the launching does some strange linking of libraries and thats why I am missing stuff like the twisted set of modules etc, it got twisted's main file but not its sub files, I am guessing the folder in the same dir that twisted file is in will contain what I need. Do I need to add all those folders to my PYTHONPATH?
Ha! I tried running python from Qpython's app w/ a fresh install and 'help()' didn't work there either.
2) Its 'from PIL import Image'
I'm starting to think i had it right the first time, irony.
Related
i want to alias ls='ls --color=always'. is there something like a .bashrc file for busybox sh?
bilclintonsdaman said:
i want to alias ls='ls --color=always'. is there something like a .bashrc file for busybox sh?
Click to expand...
Click to collapse
Just had a look at the busybox source and it says it uses the contents of environment variable ENV as a startup script so you could do
Code:
ENV=/system/sd/.bashrc ash
and it'll read /system/sd/.bashrc for your startup commands. Altrernatively, if you invoke it as a login shell (ash -l), it'll source /etc/profile then .profile from the current directory so if you create /system/sd/.profile to contain alias ls='ls --color=always' then as long as you do this
Code:
cd /system/sd
ash -l
you'll have your alias (I just tried this with JF1.51 and it worked great).
I also saw that it will record command history to the file named in HISTFILE so you may want to make your startup script look like this
Code:
alias ls='ls --color=always'
HISTFILE=/system/sd/.histfile
Also, keep in mind that this isn't bash -- you need to use ash shell scripting semantics.
Sweet! Thanks so much
~/.PROFILE
if you edit (may need to create it first) the .profile file in your home directory you shouldn't have an issue
i have the following in my ~/.profile file:
Code:
alias dir='ls -Alp'
alias cls='clear'
The next time you log in, you'll have your alias's
pre-compiled gnu bash
I can't remember where I found it, however, if you know enough to set it up, I have a pre-compiled gnu bash 3.2 file that allows you to execute something like this:
su -c '/path/to/bash --rcfile /path/to/.bashrc'
in the terminal emulator and you'll execute a bash shell with the .bashrc
I attached the pre-compiled gnu bash 3.2 in a zip file on the post, good luck getting it running! google is your friend!
I also compiled bash 4.0 for myself to use, but its kind of buggy since it was actually one of the first binaries that i've ever compiled on linux but it works! its just really slow >.>
I followed this tutorial to compile it
http://www.kbrandt.com/category/bash
I wanted to start a thread to post ASE scripts. They support three different languages and while gscript is amazing, this seems to have a lot of availability for saving the time of making entire programs for one or two functions that don't need an entire UI. Plus they can run after you close ASE, so its not a once and done environment. I would like to compile scripts here to make them easy to find.
Mods: This is not a build related topic, it spans all builds. It is not a duplicate, as the only searchable post was a link to the program. It is development because while the scripts can replace programs (in which case id post in app forum), I want to use this to do nodding and on-the-fly enhancements (development forum)
Good idea. I'm going to bump this
This just rocked my world.
ASE Blog
ASE Google Code page
ASE Faq
ASE Lua API
ASE Python API
ASE User Guide
Download ASE 0.7a
Am I the only person who thinks that ASE is completely useless ?
Actually, the method used is a HUGE hack (using JSON embedded in a TCP socket is not the cleaner thing I saw) -- ok I'm not so deeply into ASE source code, but still.
... and, the API available is very very lightweight compared to Android's standard library.
Why not having an app which just exports the current Context object into a Beanshell context ? (and maybe having access to the interpreter via adb). Here, we could have access to the whole Java APIs and do nearly exactly what we can do know using plain Java code. It would be clearly awesome !
A better thing would be using Groovy, but it doesn't seem to like dx.
I've already tried to launch the Beanshell interpreter via ASE, but it fails (when the same script works on my computer).
Anyone make (or find) any cool scripts?
I honestly like the idea of the ASE scripting because it gives people the ability to write scripts and learn about it.
Great!
This is great. Just one thing I'd change: It would be nice to split the daemon package and the language support packages.
I, for one, have debian installed and already running a python environment with many extensions installed. I'd prefer to install just the "service" part of ASE, copy android.py to my site-packages directory and integrate it into existing scripts. I'd keep ASE running on a fixed port and start modifying existing scripts to utilize the ASE service.
Mini Howto: Using ASE from debian
I wanted to use ASE from the debian installed on my android phone and did some minor patching to accommodate the fact that debian still uses python 2.5 whereas ASE requires python 2.6.
Here's how you do it:
Install the required packages:
Code:
# if you don't have python already
apt-get install python
# python 2.5 doesn't have json but this package will do.
apt-get install python-simplejson
Copy android.py from ASE to debian:
Code:
cp /data/data/com.google.ase/python/lib/python2.6/android.py /usr/lib/python2.5/site-packages/android.py
Apply this patch to android.py, to remove python 2.6 dependencies:
Code:
cd /
patch -p0 <<EOF
--- /data/data/com.google.ase/python/lib/python2.6/android.py 2009-06-14 22:48:06.000000000 +0000
+++ /usr/lib/python2.5/site-packages/android.py 2009-06-15 00:58:31.000000000 +0000
@@ -14,7 +14,7 @@
__author__ = 'Damon Kohler <[email protected]>'
-import json
+import simplejson as json
import os
import socket
import sys
@@ -25,7 +25,8 @@
class Android(object):
def __init__(self):
- self.conn = socket.create_connection(('localhost', PORT))
+ self.conn = socket.socket()
+ self.conn.connect(('localhost', int(PORT)))
self.client = self.conn.makefile()
self.id = 0
EOF
That's it.
To use it:
Activate ASE and start a terminal. (I hope future versions of ASE will run the service independent of the terminal and will no longer require this).
In your debian terminal:
Code:
export AP_PORT=$(netstat -napt|sed -n 's/^tcp.*127.0.0.1:\([0-9]*\).*LISTEN.*ase$/\1/gp')
python
The above export is required because ASE currently uses a random port. I hope future versions of ASE will allow selecting a fixed one.
Now you can use ASE from your debian's python, the same way you would in ASE's terminal:
Code:
Python 2.5.2 (r252:60911, Nov 15 2008, 00:34:24)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import android
>>> a=android.Android()
>>> a.makeToast('debian')
{u'result': None, u'id': 0, u'error': None}
>>>
Now you can start porting scripts to use ASE
I have been trying to figure out how to reboot my phone using any of the interpreters in ASE.
I have tried the following in Lua.
os.execute("reboot")
and I get permission denied.
I have tried
os.execute("su")
os.execute("reboot")
but then the terminal changes from $ to # and nothing happens.
Get the same results using os.system() commands in python.
Anyone have any ideas on how to make this work? Seems like it ought to be simple but I have no experience in these languages.
Try "su -c /system/bin/reboot".
mod1 said:
Try "su -c /system/bin/reboot".
Click to expand...
Click to collapse
Thanks for the help but I still got "not permitted!"
Script to query Amazon
This isn't much but I'm an Amazon book junkee and I've tried all the bar code scanners in the market and none of them will just take me directly to the Amazon page for an item I scan without having to click several different buttons first.
So, without further adieu:
Code:
import android
"""start barcode scanner and scan barcode"""
droid = android.Android()
code = droid.scanBarcode()
ISBN = (code['result']['SCAN_RESULT'])
"""open browser at the first google i'm feeling lucky link which typically will be the amazon page for the item"""
url = "http://www.google.com/search?hl=de&q=site%3Aamazon.com+" + ISBN + "&meta=lr%3Dlang_en&btnI=I'm+feeling+lucky"
droid.startActivity('android.intent.action.VIEW', url)
The only issue is, sometimes, the bar code scanner goes into some kind of endless loop and just keeps restarting every time I scan. I think it's a bug in the zebra crossing app, but any help would be appreciated.
I must say, I am very excited about being able to use python on my G1, as maybe I'm just an idiot, but I can't seem to get into the standard sdk with its multiple points of entry, and having to deal with eclipse. I also really can't wait for the ability to write and run full fledged apps that can take advantage of the full widget set.
@jinx10000
I figured out how to execute os commands as root.
I wrote a small python script called testing.swapon.py that could obviously not be successfully executed as a regular user containing:
Code:
import os
os.system("swapon /dev/block/mmcblk0p3")
and placed it in /system/sd.
Then at the terminal emulator, not the ase but the regular terminal I downloaded from the market, and as the regular user, i.e. not root, I executed
Code:
$ su -c "/data/data/com.google.ase/python/bin/python /system/sd/testing.swapon.py"
And surprise, after running free, I noted that my swap partition was indeed mounted. And just to be sure, I unmounted it as root and did the whole thing over again. So, it looks like we can do some interesting root stuff with the ase scripting languages. Now, people just need to get interested in this so we can get some momentum and some cool scripts written.
The previously mentioned "export AP_PORT" doesn't work for me with the new ASE (r16)
The following one does:
export AP_PORT=$(netstat -napt|sed -n 's/^tcp.*127.0.0.1:\([0-9]*\).*LISTEN.*com\.google\.ase\?:\?/\1/gp'|sed '/.*/q')
Is there an update to this post now that I can run python 2.6 in my debian chroot and ASE now has a server? I'm kinda confused....
mod1 said:
I wanted to use ASE from the debian installed on my android phone and did some minor patching to accommodate the fact that debian still uses python 2.5 whereas ASE requires python 2.6.
Here's how you do it:
Install the required packages:
Code:
# if you don't have python already
apt-get install python
# python 2.5 doesn't have json but this package will do.
apt-get install python-simplejson
Copy android.py from ASE to debian:
Code:
cp /data/data/com.google.ase/python/lib/python2.6/android.py /usr/lib/python2.5/site-packages/android.py
Apply this patch to android.py, to remove python 2.6 dependencies:
Code:
cd /
patch -p0 <<EOF
--- /data/data/com.google.ase/python/lib/python2.6/android.py 2009-06-14 22:48:06.000000000 +0000
+++ /usr/lib/python2.5/site-packages/android.py 2009-06-15 00:58:31.000000000 +0000
@@ -14,7 +14,7 @@
__author__ = 'Damon Kohler <[email protected]>'
-import json
+import simplejson as json
import os
import socket
import sys
@@ -25,7 +25,8 @@
class Android(object):
def __init__(self):
- self.conn = socket.create_connection(('localhost', PORT))
+ self.conn = socket.socket()
+ self.conn.connect(('localhost', int(PORT)))
self.client = self.conn.makefile()
self.id = 0
EOF
That's it.
To use it:
Activate ASE and start a terminal. (I hope future versions of ASE will run the service independent of the terminal and will no longer require this).
In your debian terminal:
Code:
export AP_PORT=$(netstat -napt|sed -n 's/^tcp.*127.0.0.1:\([0-9]*\).*LISTEN.*ase$/\1/gp')
python
The above export is required because ASE currently uses a random port. I hope future versions of ASE will allow selecting a fixed one.
Now you can use ASE from your debian's python, the same way you would in ASE's terminal:
Code:
Python 2.5.2 (r252:60911, Nov 15 2008, 00:34:24)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import android
>>> a=android.Android()
>>> a.makeToast('debian')
{u'result': None, u'id': 0, u'error': None}
>>>
Now you can start porting scripts to use ASE
Click to expand...
Click to collapse
bump ~ 10 ~
Paul22000 said:
Anyone make (or find) any cool scripts?
Click to expand...
Click to collapse
I did a toggleswap.sh script ages ago
it gets around the not having su thing
not the most secure thing in the world, as once you have su remember ase getting root for
sh /sqlite_stmt_journals/ToggleSwap.sh
ase will always be able to execute that script, without prompting
but you can add a shortcut to the script ( longpress home and select ase )
Code:
#!/system/bin/sh
tmpscript=/sqlite_stmt_journals/ToggleSwap.sh
ToggleOn ()
{
echo "#!/system/bin/sh
for i in \`ls /dev/block/mmcblk0p*\`;do
swapon \$i 2>/dev/null
if [ \"\$?\" = \"0\" ];
then
break
fi
done" > $tmpscript
return
}
ToggleOff ()
{
echo "#!/system/bin/sh
for i in $swapon;do
swapoff \$i
done" > $tmpscript
return
}
swapon=`awk '$1 !~ /^File/ { print $1 }' /proc/swaps`
if [ "$swapon" = "" ];
then
ToggleOn
else
ToggleOff
fi
su -c "sh $tmpscript"
free
rm $tmpscript
Two very simple python scripts for adding a new contact and composing a new text message:
New contact:
Code:
import android
droid = android.Android()
droid.startActivity('android.intent.action.INSERT', 'content://contacts/people')
droid.makeToast('Add new contact')
droid.exit()
New message:
Code:
import android
droid = android.Android()
droid.startActivity('android.intent.action.SENDTO', 'sms:')
droid.makeToast('New message')
droid.exit()
sign files with a right click (Ubuntu) (Thanks Amon_RA)
-----------------------------------------------------------------------------------------------------------------
This little novice, 2-line script will help you sign update.zip files directly from any terminal window if you have the Android SDK set up on your machine. It might be pointless to some, but I thought it would be a nice idea to share.
Navigate to your Android SDK directory.
Create a folder and name it "sign".This is where you will put the update.zip that you want to sign.
Download the attached testsign.jar file [extract from zip] and move it to the new /sign directory in your Android SDK.
Navigate to your /tools directory and Right-Click > Create Document > Empty File.
Give it a name without extension.example: sign
Right-Click > Open with "Text Editor" and add the following:Change the directories according to your setup.
#!/bin/sh
java -classpath /AndroidSDK/sign/testsign.jar testsign /AndroidSDK/sign/update.zip /AndroidSDK/sign/update-signed.zip
Click to expand...
Click to collapse
Give it executable permissions with the terminal -
Code:
cd /YOUR-SDK-DIRECTORY/tools/
chmod a+x sign
Now you can simply drop the update.zip to your /sign directory and from the terminal type:
Code:
sign
and it will sign it without having to add the long command yourself.
Of course you can edit the script to fit your needs.
---- Optional ----
By making a link (right-click > Make Link) of your /sign directory and adding it to your Desktop, you can drag and drop update.zip directly to this link and sign. This save you some time in the signing process and you have access to it from your Desktop.
---- Optional ----
Thank you Cyanogen for this reply.
mods, please sticky this as i'm sure many will find this very informative
Perfect howto, just works like a charm Thanks to the author!
Thank you so much! Just started using ubuntu in a VM. Think you could write up a guide on setting up eclipse? That'd be absolutely super. Thanks again lol. Helped me sign files + set up the sdk. Great work.
alritewhadeva said:
Thank you so much! Just started using ubuntu in a VM. Think you could write up a guide on setting up eclipse? That'd be absolutely super. Thanks again lol. Helped me sign files + set up the sdk. Great work.
Click to expand...
Click to collapse
Well, setting up eclipse is fairly simple!
download Eclipse
unzip it any directory/AndroidSDK/Eclipse | /home/wddglr/Apps/Eclipse
set up the ADT following the information in this page: [http://developer.android.com/sdk/1.5_r3/installing.html]
wddglr said:
Well, setting up eclipse is fairly simple!
download Eclipse
unzip it any directory/AndroidSDK/Eclipse | /home/wddglr/Apps/Eclipse
set up the ADT following the information in this page: [http://developer.android.com/sdk/1.5_r3/installing.html]
Click to expand...
Click to collapse
Ah thank-you. I'll PM you if i run into any problems if thats okay. I'm a noob with ubuntu just set it up yesterday.
i love you man j/k
THANK UUUUUUUUUU so much man
if you use lots of different named update zips.
This is step 6
#!/bin/sh
echo -n "Source Zip Filename : "
read input
echo -n "Output Zip Filename : "
read output
java -classpath /androidsdk/sign/testsign.jar testsign /androidsdk/sign/"$input" /androidsdk/sign/"$output"
echo "Finished signing $input as $output"
Click to expand...
Click to collapse
Just input the source file and the output and it does the rest.
Was useful for me as I sign different zips.
Use as you wish, thanks to wddglr.
I don't know why I can never get this to work.
This is exactly what I see when I ls /AndroidSDK/sign:
[email protected]:~$ ls /AndroidSDK/sign
testsign.jar update.zip
[email protected]:~$ sign
Exception in thread "main" java.lang.NoClassDefFoundError: testsign
at gnu.java.lang.MainThread.run(libgcj.so.90)
Caused by: java.lang.ClassNotFoundException: testsign not found in gnu.gcj.runtime.SystemClassLoader{urls=[], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.90)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at gnu.java.lang.MainThread.run(libgcj.so.90)
Click to expand...
Click to collapse
Binary100100 said:
I don't know why I can never get this to work.
This is exactly what I see when I ls /AndroidSDK/sign:
[email protected]:~$ ls /AndroidSDK/sign
testsign.jar update.zip
Click to expand...
Click to collapse
I was wondering if you were you able to solve this? Becouse I'm getting the same.. I'm thinking it has something to do with jave. But not sure what I need to do to fix it.. thanks for any info ....
yea me toooo
edit i figured it out
Code:
# Right-Click > Open with "Text Editor" and add the following:
Change the directories according to your setup.
Quote:
#!/bin/sh
java -classpath [B]/AndroidSDK[/B]/sign/testsign.jar testsign /[B]AndroidSDK[/B]/sign/update.zip /AndroidSDK/sign/update-signed.zip
yeah that is not where my tools are lol
wddglr said:
sign files with a right click (Ubuntu) (Thanks Amon_RA)
-----------------------------------------------------------------------------------------------------------------
This little novice, 2-line script will help you sign update.zip files directly from any terminal window if you have the Android SDK set up on your machine. It might be pointless to some, but I thought it would be a nice idea to share.
Navigate to your Android SDK directory.
Create a folder and name it "sign".This is where you will put the update.zip that you want to sign.
Download the attached testsign.jar file [extract from zip] and move it to the new /sign directory in your Android SDK.
Navigate to your /tools directory and Right-Click > Create Document > Empty File.
Give it a name without extension.example: sign
Right-Click > Open with "Text Editor" and add the following:Change the directories according to your setup.
Give it executable permissions with the terminal -
Code:
cd /YOUR-SDK-DIRECTORY/tools/
chmod a+x sign
Now you can simply drop the update.zip to your /sign directory and from the terminal type:
Code:
sign
and it will sign it without having to add the long command yourself.
Of course you can edit the script to fit your needs.
---- Optional ----
By making a link (right-click > Make Link) of your /sign directory and adding it to your Desktop, you can drag and drop update.zip directly to this link and sign. This save you some time in the signing process and you have access to it from your Desktop.
---- Optional ----
Thank you Cyanogen for this reply.
Click to expand...
Click to collapse
I tried every way I could, and as stupid as I am, I could not get it to work!!!
[email protected]:~$ sign
bash: sign: command not found
[email protected]:~$ cd /home/ccriffman/android/tools
[email protected]:~/android/tools$ sign
bash: sign: command not found
[email protected]:~/android/tools$ cd /home/ccriffman/android
[email protected]:~/android$ sign
bash: sign: command not found
[email protected]:~/android$ cd /sign
bash: cd: /sign: No such file or directory
[email protected]:~/android$ cd /home/ccriffman/android/sign
bash: cd: /home/ccriffman/android/sign: No such file or directory
[email protected]:~/android$ cd /tools
bash: cd: /tools: No such file or directory
[email protected]:~/android$ cd tools
[email protected]:~/android/tools$ sign
bash: sign: command not found
[email protected]:~/android/tools$ cd sign
bash: cd: sign: Not a directory
[email protected]:~/android/tools$ sign
bash: sign: command not found
[email protected]:~/android/tools$
joe v said:
I was wondering if you were you able to solve this? Becouse I'm getting the same.. I'm thinking it has something to do with jave. But not sure what I need to do to fix it.. thanks for any info ....
Click to expand...
Click to collapse
Yeah, I got it to work. The problem was with my Java.
testsign.jar in wrong spot
I got mine fixed. I had testsign.jar inside of the testsign folder inside the sign folder.
testsign.jar needs to be in the 'root' of the sign folder, or you need to modify the sign script to point to the correct location.
pconwell said:
I got mine fixed. I had testsign.jar inside of the testsign folder inside the sign folder.
testsign.jar needs to be in the 'root' of the sign folder, or you need to modify the sign script to point to the correct location.
Click to expand...
Click to collapse
..... damnit.
I did the same thing
======EDIT=======
Now I am getting this error:
sign
No command 'sign' found, did you mean:
Command 'bsign' from package 'bsign' (universe)
Command 'psign' from package 'radiance' (universe)
sign: command not found
Click to expand...
Click to collapse
Help?
I guess it means I've failed???
This script worked great, I really appreciate it. I did modify it a bit so that I don't have to necessarily sign update.zip every time. It is similar to the script posted on the first page, but rather than it asking for the input and output, you simply add parameters to the sign command. For example:
Code:
sign <input> <output>
See the code below, make sure you change the directory to where you have the sign folder located.
Code:
#!/bin/sh
java -classpath /opt/android/sign/testsign.jar testsign /opt/android/sign/$1 /opt/android/sign/$2
echo "Finished signing $1 as $2"
Hope this helps anyone.
An even better modification is to make it only take ONE parameter:
#!/bin/bash
mv $1 /tmp/$$-$1
java -classpath /opt/android/sign/testsign.jar testsign /tmp/$$-$1 $1
rm /tmp/$$-$1
Note that this form is also independent of the location of the archive to sign -- it is nicer to enter that particular directory and just run "sign file.zip".
You should really mention that the tools directory has to be added to $PATH..
Not everyone has this, if you don't then simply typing sign will not work
wedsxcrfv said:
You should really mention that the tools directory has to be added to $PATH..
Not everyone has this, if you don't then simply typing sign will not work
Click to expand...
Click to collapse
Well it should be correctly assumed that $PATH was correctly set when they installed the Android SDK, because if they followed the instructions provided by the SDK's documentation then it says to set the $PATH var in "~/.bashrc" or "~/.bash_profile".
From: http://developer.android.com/sdk/installing.html
On Linux, edit your ~/.bash_profile or ~/.bashrc file. Look for a line that sets the PATH environment variable and add the full path to the tools/ directory to it. If you don't see a line setting the path, you can add one:
export PATH=${PATH}:<your_sdk_dir>/tools
Click to expand...
Click to collapse
*****************************************************************************************************************************************************
Credit for discovering this method goes to Sr. Staff gurus @_that (bet you could have guessed) and @becomingx for parsing GNU code to figure out file naming limitations (no dots!) to make this work.
******************************************************************************************************************************************************
This short Guide accompanies the need to run my B2R startup script (or any script) as root at boot. If you are rooted and have busybox installed on a stock ROM or any ROM that does not have init.d support thru init.rc, here's how you can add it. This is an alternative method to either using Script Manager (SManager) or hijacking the install-recovery.sh file directly to run a startup script. Enabling this support allows you to be able to run all executable scripts located in init.d as root at boot.
IMPORTANT: Your init script name can NEITHER have any dots in the filename NOR use an extension. Name it something like autostart or start-up or init_script. Also when you write a script, NEVER forget to start it with the hash-bang-path to shell (#!/system/bin/sh) and NEVER forget to press ENTER after the last character of the last line of code. You can't just use any simple text editor to create the file - you must pay close attention to "line ends". I use ES Note Editor on device and Notepad++ configured for UNIX/OSX line ends on PC. Always save the file AS PLAIN TEXT. Read "Additional Information" below on line ends.
[NOTE: /system/etc = /etc (symlink)]
1. Mount your /system rw
Code:
mount -o remount,rw /system
2. Make directory /system/etc/init.d
Code:
mkdir /system/etc/init.d
3. Create a shell script (using a text editor with UNIX line ends [LF only] ) named "/system/etc/install-recovery.sh" with the following contents:
Code:
#!/system/bin/sh
/system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d
4. Put your init script in init.d and remember to make both /system/etc/install-recovery.sh and your script in /system/etc/init.d executable.
Code:
cd /system/etc
chmod 755 install-recovery.sh
cd /system/etc/init.d
chmod 755 name_of_your_init_script
5. Immediately reboot or if not, mount your /system ro
Code:
mount -o remount,ro /system
If you have busybox installed in /system/xbin this enables support for running init.d scripts from ROMs that do not offer native support thru init.rc.
Additional Information:
Every file has what are know as line ends or more technically end of line (EOL) conversions. These are HIDDEN characters that you normally don't see (if the line end are in the native OS format) at the end of lines in a text editor when editing files. This is the character that tells the OS where one line stops and the next starts in any file. In order to see the line ends you must enable "show all characters".
Your text editor must support UNIX line ends (LF only, not CR + LF = CRLF). Do NOT use Windows Notepad as it only creates Windows line ends (CRLF).
Always use UNIX line ends - a Windows editor like Notepad will create CRLF line ends, while your shell script MUST use LF line ends or it will fail to execute. Otherwise your first line will look like this to Linux:
Code:
#!/system/bin/sh^M
The ^M above is the common convention to display the control character Ctrl+M, which is CR (carriage return) before the LF (line feed) or (CRLF). The consequence is that the system can't find your shell under the name "sh^M" (or any subsequent command "some_command^M") and your script will fail.
This is VERY important to understand and also how to configure any cross-platform text editor. Using notepad++ in Windows without changing the default settings still results in CRLF at the end of lines because it knows its running in Windows and thinks you want Windows line ends. In order to change this behavior, Under the Edit menu find EOL conversion, and select Unix/OSX format. Also toggle the paragraph symbol on the top bar (backwards P with double verticles; show all characters) and now its clear as day what line ends you have, where they are, and if you have one after the end of the last line or not. Now its WYSIWYG. Once these setting are toggled, saving the file in Windows results in Unix/OSX line ends (LF) and when you open notepad++ the next time the settings are retained. See screenshot before attachment at the end of this post.
Example for changing default EOL conversion to Unix LF for an older version of notepad++:
http://techtips-it.blogspot.com/2011/04/can-i-convert-file-format-in-notepad.html
If done correctly, the output you will see if VIEWED (not edited) using Windows notepad will show a small hollow rectangle representing each LF. You will see one for each line end, and two together at the end of the last line itself - the first is the EOL LF for that line, and the subsequent is the LF you entered after the last line. If notepad just shows what you would normally see in the XDA code block with no extra special characters as described, you have Windows line ends and your script will fail to execute.
If you have multiple scripts to run at boot, the real purpose of init.d, you should name your init scripts prepended with two digits between 00 and 99. (Fairly) Evenly divide the range into 3 groups like 2# (20-29), 5# (50-59), and 8# (80-89). Scripts in the 20 series will be run first, followed by 50 series scripts, ending with 80 series scripts. They will be executed from lowest number to highest number, in that order. This allows you to define the load order for a group of init scripts. We didn't use 00-19 or 90-99 in case we need to put a future script before the first or after the last one without having to rename the rest of the scripts to do so.
Example init script names: 20firststart, 50mid_start, 80end-boot
******************************************************************************************************************************************************
Download the attachment and remove the txt extension and copy it into /system/etc and make sure it is executable. Make directory /system/etc/init.d, put your executable boot scripts in there, and reboot to run your executable init.d scripts as root.
This method replaces the depreciated method of directly hijacking install-recovery.sh with a single boot script run as root. Why have only one when you can have many?
Linkback to dev thread
http://forum.xda-developers.com/showthread.php?t=2191777
Reserved
Sent from my LG-LS970 using xda app-developers app
elfaure said:
@_that, please review and bless.
Click to expand...
Click to collapse
elfaure said:
IMPORTANT: Your init script name can NEITHER have any dots in the filename NOR use an extension. Name it something like autostart or start-up or init_script.
Click to expand...
Click to collapse
I still recommend using the common Unix convention of 2 digits + lowercase name for init.d scripts, e.g. 50something, 60dothislater, 90somethingtodolast. The numbers allow for clearly defining the order in which multiple startup scripts are executed.
elfaure said:
Also when you write a script, NEVER forget to start it with the hash-bang-path to shell (#!/system/bin/sh) and NEVER forget to press ENTER after the last character of the last line of code. You can use any simple text editor to create the file. I use ES Note Editor on device and Notepad++ on PC. Always save the file AS PLAIN TEXT.
Click to expand...
Click to collapse
And always use UNIX line ends - a Windows editor like Notepad will create CRLF line ends, while your shell script MUST use LF line ends. Otherwise your first line will look like this to Linux:
Code:
#!/system/bin/sh^M
The ^M above is the common convention to display the control character Ctrl+M, which is CR (carriage return) before the LF (line feed). The consequence is that the system can't find your shell under the name "sh^M" and your script will fail.
elfaure said:
4. Remember to make it executable and to create the /system/etc/init.d directory.
Click to expand...
Click to collapse
You already created init.d in step 1.
Looks like it could work like this. If you want to be sure, remove your existing scripts and rmdir your init.d directory, then follow your own guide and see if everything is OK. Then you can bless it yourself. In software development, peer review is always good, but testing is even more important.
_that said:
I still recommend using the common Unix convention of 2 digits + lowercase name for init.d scripts, e.g. 50something, 60dothislater, 90somethingtodolast. The numbers allow for clearly defining the order in which multiple startup scripts are executed.
And always use UNIX line ends - a Windows editor like Notepad will create CRLF line ends, while your shell script MUST use LF line ends. Otherwise your first line will look like this to Linux:
Code:
#!/system/bin/sh^M
The ^M above is the common convention to display the control character Ctrl+M, which is CR (carriage return) before the LF (line feed). The consequence is that the system can't find your shell under the name "sh^M" and your script will fail.
You already created init.d in step 1.
Looks like it could work like this. If you want to be sure, remove your existing scripts and rmdir your init.d directory, then follow your own guide and see if everything is OK. Then you can bless it yourself. In software development, peer review is always good, but testing is even more important.
Click to expand...
Click to collapse
Thanks for the review! I will make some edits, test drive the guide, and bless it myself. I was already going to add the two digit numerical discussion. I'm not trying to get you to do any extra or my work here, God knows you are a very busy multi-tasking hundreds of tasks , I just thought I was on newb patrol after posting a non-working script and then mandated to your must review list.
Is this method works on other phone too?
I really do want the init.d support on stock rom
Sorry for my bad English...
Sent from my HTC Desire 200 using XDA Premium 4 Mobile app
dicks93277 said:
Is this method works on other phone too?
I really do want the init.d support on stock rom
Click to expand...
Click to collapse
The method is reasonably generic that it is worth trying on your device.
so sad that i can't make this work on my phone
but still thanks for your reply @_that
Awesome it works on my Panasonic T41 running MIUI 5 beta
Could you tell how to do the same thing from init.rc ???
and also one script is not working
Code:
#!/system/bin/sh
su
mount -o rw,remount /
mkdir -p /rex
mount -o bind /data/data/com.spartacusrex.spartacuside/files/system /rex
mount -o rw,remount /system
mkdir -p /system/vendor/bin
mount -o /rex/bin /system/vendor/bin
Is there any thing wrong with it ?? I used unix terminators and also set the permissions to 755
uttarayan21 said:
Awesome it works on my Panasonic T41 running MIUI 5 beta
Could you tell how to do the same thing from init.rc ???
and also one script is not working
Code:
#!/system/bin/sh
su
mount -o rw,remount /
mkdir -p /rex
mount -o bind /data/data/com.spartacusrex.spartacuside/files/system /rex
mount -o rw,remount /system
mkdir -p /system/vendor/bin
mount -o /rex/bin /system/vendor/bin
Is there any thing wrong with it ?? I used unix terminators and also set the permissions to 755
Click to expand...
Click to collapse
The 'su' command with no arguments starts an interactive shell, everything after 'su' waits for the user to exit that shell, which you can't do. Init.rc and subsequent scripts are run as root anyway, including init.d scripts, so just delete the 'su' line and it should work.
Sent from my LGL41C using Tapatalk
Kor1134 said:
The 'su' command with no arguments starts an interactive shell, everything after 'su' waits for the user to exit that shell, which you can't do. Init.rc and subsequent scripts are run as root anyway, including init.d scripts, so just delete the 'su' line and it should work.
Sent from my LGL41C using Tapatalk
Click to expand...
Click to collapse
Thanks !!! It worked !!!!
uttarayan21 said:
Thanks !!! It worked !!!!
Click to expand...
Click to collapse
You're welcome [emoji6]
Sent from my LGL41C using Tapatalk
Why don't use service from init.rc ??
elfaure said:
*************************************,
3. Create a shell script (using a text editor with UNIX line ends [LF only] ) named "/system/etc/install-recovery.sh" with the following contents:
Code:
#!/system/bin/sh
/system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d
Click to expand...
Click to collapse
But it is better to add a service to init.rc and launch sysinit from there for init.d support !!!
Maybe you should update your guide with that !!!
:laugh: :good:
uttarayan21 said:
But it is better to add a service to init.rc and launch sysinit from there for init.d support !!!
Maybe you should update your guide with that !!!
:laugh: :good:
Click to expand...
Click to collapse
Changing init.rc requires repacking the boot image.
_that said:
Changing init.rc requires repacking the boot image.
Click to expand...
Click to collapse
Yeah it does but if you install SuperSU then the install-recovery.sh file will be modified and init.d will be lost !!!
Now tested up to downloading AOSP and make toolbox you should be all set
Please give thanks to this thread: https://forum.xda-developers.com/newreply.php?do=newreply&p=43622764
Warning: I hacked my way through this stuff a few weeks ago I am not an expert!
How to compile Android Open Source Code modules
I don't compile C code on Windows machines I have no idea about that.
Notice
This guide is a quick and dirty how to make a module. It will not cover finalizing setting up the source codes for your device. It is only my goal to enable you to compile binaries such as grep, toolbox, dumpstate, dalvikvm, jack and etc.
===>] Setup Ubuntu 64bit [<===Unplug that Windows drive, plug in a fresh hard drive and install Ubuntu latest/greatest. Ignore the recommendation to downgrade gnu make!, for now.
Open a terminal and issue these commands (warning ppa repository for OpenJDK 7 is said to have a security issue?, isn't being updated?.. whatevs it works)
Code:
sudo apt-get update
sudo apt-get upgrade
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get install openjdk-7-jdk
sudo apt-get install openjdk-8-jdk
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
sudo apt-get install git ccache automake lzop bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 g++-multilib python-networkx libxml2-utils bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev squashfs-tools pngcrush schedtool dpkg-dev liblz4-tool make optipng
(choose Java 1.7 in the following way)
Code:
sudo update-alternatives --config java
(let me know if I missed anything please)
"Tried the Android SDK only it is missing too many things we need as a developer"
===>] Setup Android Studio SDK & NDK [<===Installation Paths:
*** I install to /home/username/Android and /home/username/Android/Sdk and /home/username/Android/Sdk/ndk-bundle ***
NOTE: from here forward username will == droidvoider
Note: Android Studio IDE isn't necessary only the SDK & NDK are needed to compile AOSP.
Install Android Studio Proper: (don't worry about setting up paths we will cover that, just install it)
https://developer.android.com/studio/install.html
or
SDK Only:
Typically we install these things manually by creating the directory then just unzipping the files there.
https://developer.android.com/studio/index.html#linux-bundle (scroll down for sdk only)
Code:
mkdir /home/droidvoider/Android
mkdir /home/droidvoider/Android/Sdk
(then unzip the sdk zip to that directory. I recommend the file explorer copy/paste right click uncompress and done.)
https://dl.google.com/android/repository/tools_r25.2.3-linux.zip
Install NDK through the SDK Manger:
(from terminal 'studio.sh' and then configure, and then sdk manger --- if this is hard to figure out tell me I will elaborate)
or
Manually Install Native Development Kit -- 'c programming support'
Download the Native Development Kit from Google: https://developer.android.com/ndk/downloads/index.html
Code:
mkdir /home/droidvoider/Android/Sdk/ndk-bundle
Then just unzip the ndk files into the directory we created above.
===>] Setup your toolchain [<===** This example is arm64-v8a aarch64 **
1. Navigate to /home/droidvoider/Android/Sdk/ndk-bundle/build/tools and then open a terminal "right click open area"
2. mkdir /home/droidvoider/toolchains
3. ./make_standalone_toolchain.py --arch arm64 --api 23 --stl=libc++ --install-dir /home/mm/toolchains/aarch64-linux-android-4.9
4. cd /home/droidvoider
5. gedit .bashrc and morph this in at the bottom.. (AND edit or replace the existing PATH variable)
DON'T just PASTE IN *my* $PATH export!! I included my entire path statements to show you.
Code:
export PATH=$PATH:/usr/local/android-studio/bin:/home/droidvoider/Android/Sdk/platform-tools:/home/droidvoider/Android/Sdk/ndk-bundle:/home/droidvoider/Android/Sdk/tools
I feel this is human readable, for example change Android_Build_Out to be on your desktop instead if you want.
Code:
export PATH=$PATH:/home/droidvoider/toolchains/aarch64-linux-android-4.9
export NDK=/home/droidvoider/Android/Sdk/ndk-bundle
export SYSROOT=$NDK/platforms/android-23/arch-arm64
export TARGET=aarch64-linux-android
export HOST=$TARGET
export BUILD=x86_64-linux
export ANDROID_NDK_BIN=/home/droidvoider/toolchains/aarch64-linux-android-4.9/bin
export CC=$ANDROID_NDK_BIN/aarch64-linux-android-gcc-4.9
export CPP=$ANDROID_NDK_BIN/aarch64-linux-android-g++
export AR=$ANDROID_NDK_BIN/aarch64-linux-android-ar
export OUT_DIR_COMMON_BASE=/home/droidvoider/Android_Build_Out
Note: You might want to setup an alternate toolchain also but this is all of the puzzle pieces.
===>] Google's version of this How To -- Just for reference [<===https://source.android.com/source/requirements.html
https://source.android.com/source/initializing.html
===>] Install the repo tool [<===https://source.android.com/source/downloading.html
(don't type repo init or repo sync --- I will be taking back over from there on the next page)
Added Repair Notes -- Not part of the install!
Have you accidentally installed or removed something you shouldn't have? (welcome to development, here try this before reinstall)
sudo apt-get clean
sudo apt-get update
sudo apt-get install -f
sudo dpkg -a --configure
sudo apt-get dist-upgrade
sudo apt-get install -f
sudo dpkg -a --configure
Selecting the correct AOSP branch and downloading it.
Tested up to downloading AOSP and make toolbox -- you should be all set
===>] Match your build number to it's AOSP sources [<===preface: You can get this from your device if you're on the same build id as your the available source code from your vendor for your device. Otherwise you need to open the AP file from the firmware that matches those available sources to extract the system.img, to extract build.prop. I explain how to open a system.img file below under retrieving your hardware drivers. build.prop is in the main directory of system.img
(Many times the build number is the same. For me I believe all of MM builds are using this number.)
Assumes sources match current device, worked out true in my case
1. Plug in your device and get it connected. (DEVELOPER OPTIONS|USB DEBUGGING) and select allow on device
2. Retrieve the build number that matches the available sources for your device.
From your ubuntu terminal retrieve the build id using this command:
Code:
adb shell getprop | grep 'ro.build.id'
Yields something similar to this: [ro.build.id]: [MMB29K]
3. Match it up to the Nexus build numbers (This info is for AT&T Note 5 Marshmallow MMB29K, get your specific build number!)
https://source.android.com/source/build-numbers.html#source-code-tags-and-builds
MMB29K android-6.0.1_r1 Marshmallow Nexus 5, Nexus 5X, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg)
===>] Bring down a specific AOSP source branch [<===
4. Make a directory for the source code.
Code:
mkdir /home/droidvoider/Desktop/AOSP_Android_6.01_r1
5.
Code:
cd /home/droidvoider/Desktop/AOSP_Android_6.01_r1
6. Bring down the sources, this one is approximately 13 gigabytes
Code:
repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r1
repo sync
===>] I'm not sure the rest of this is needed [<===For compiling toolbox the remainder wasn't needed.. But I have a large list of things to do so I can't test each item. If you can't compile a specific module continue reading.
===>] Merge Vendor sources & AOSP sources [<===
7. Download the available sources for your device. In this example I downloaded PE6 Marshmallow sources for AT&T Note 5:
http://opensource.samsung.com/reception/receptionSub.do?method=sub&sub=F&searchValue=SM-N920A
8. Read the readme file from the sources platform zip to understand how to merge them into the AOSP sources. For the 2 Samsungs I've worked with the idea is to replace any directory that already exists. But if there is just one file such as core.mk only replace the one file. Then edit the .mk files as described in your readme. (and/or take info from cyanogen/lineagos) -- <I can help more, ask>
note: you probably don't need to take the configs from LineageOS and put them into your .mk files. However, if you do need to get more configs then you should get a big fat message when you type make 'modulename'. At first only edit .mk files as described by vendor device source readme file.
===>] Merge in Hardware drivers and etc [<===possibly unnecessary depends what you're doing
9. Obtain a copy of the firmware for your device that matches the version of the source code you are able to download from your vendor.
for me that was Build Number: MMB29K.N920AUCU2BPE6 but your mileage will almost certainly vary!
10. Download https://github.com/anestisb/android-simg2img
11. Unzip it right in your download folder, open the folder and then 'open in terminal'
12. Make it and then move it a directory in your path. Warning: My command puts in in the Ubuntu default /bin folder.
Code:
make
sudo mv append2simg img2simg simg2img simg2simg simg_dump.py /bin
13. Uncompress the AP file from the matching firmware and extract the system.img into it's own directory
then select that folder, right click, open in terminal
Code:
simg2img system.img sys.raw
mkdir sys
sudo mount -t ext4 -o loop sys.raw sys/
14. A drive mounted, look on your task bar it should've wiggled too. Copy the etc and vendor folders into the main folder of the sources we are merging
===>] Listing and building modules [<===Navigate to the folder where you download the sources "/home/droidvoider/Desktop/AOSP_Android_6.01_r1" and open in terminal.
Code:
make modules -- list the available modules
make <module name> -- builds a specific module
example: make dumpstate
description: Will build everything needed for dumpstate and place it in the folder we specified in our export (above step). The final build line will read install and detail the final output folder
Example successful output:
[CODE]
Install: /home/droidvoider/Android_Build_Out/Android_6.01_r1/target/product/generic/system/bin/dumpstate
===>] Android Build System, basic intro [<===Notice: I built this how to to answer the same question from 3 people regarding working with toolbox and the dirtycow exploit. So I decided to give a direct example of using toolbox.c from farm-root
#ifdef
Our makefile is Android.mk and that's where we link things together. If you look at the Android.mk file for farm-root you will notice bridge.c is used 3 different times called different 'module' names. bridge_pull, bridge_push, bridge_pull_boot. Each of these will be binaries of those names.
Inside bridge.c you will see #ifdef FARM_PULL and then you will see #else and further you will see #endif which you may have noticed matches inside the Android.mk file for the bridge modules -DFARM_PULL -DFARM_BOOT <== Notice the double define on bridge_pull_boot
toolbox.c
toolbox.c is going to be the same way. You will need to copy shared.h and shared.c into the directory where toolbox.c resides. Then edit the Android.mk, in our example:
1. Navigate to this directory and open: system/core/toolbox/Android.mk
2. CTRL + F and search for "LOCAL_MODULE := toolbox"
3. Add: LOCAL_CFLAGS += -DFARM_PULL -DFARM_BOOT (in this example add one, both or even new ones you created)
4. Navigate to the main directory of the sources, you should see a Makefile and a build_64bit.sh
5. from terminal: make toolbox
Note: I think from here you can Google it out in a few minutes if that is not the case please let me know.
Working with C cross platformUbuntu is Linux based just like Android and this makes testing blocks of code extremely easy. You of course can't use Android headers and in some rare cases you can't test the code on Ubuntu at all but in most cases you can. When I want to design something for Android I open gedit and save it as a .c file. Then I compile it using gcc -o mycode mycode.c There's plenty of examples on using gcc with linux but just understand you can do it all. Then before too much work test it on Android. (helpful commands at end of post)
My advice really is to build out your small blocks of code on your linux box but then paste them into your Android program folder, edit your Android.mk, add it to your Makefile including your 'push' section so that you can simply type make push to test it.
I am in fact trying to encourage you to learn C and not so much trying to encourage you to hack things. But I know that interest/passion is what teaches, not my words and not someone else's curriculum. So in that spirit I will do my best to give examples to help you with 'whatever' it is you are passionate about. Let me know what's missing.
Don't forget to compile for Android first
Before you can test your code you will have compiled it using the cross compiler for Android. ndk-build, or the correct gcc cross compiler. (Personally I put the .c file into a directory with Android.mk and a Makefile then just type make to build it to Android)
see examples section I will add a couple examples.
Android Developer Bridge -- a developers tool
adb is included with the Android SDK along with some other tools. Some of those tools are fastboot for unlocking bootloaders and another way of flashing. There is monitor which is a cool tool for remotely viewing processes, logcat, memory dumps and etc.
But pointedly what we will use the most is simply adb.
Using adb to test your code on locked down Android systems
Shell has fairly high privileges, you may not be aware but you can execute binaries and bash scripts. We use /data/local/tmp/ for these things. You can create a directory, add or remove files, execute your binaries and even execute shell scripts using sh script.sh
ndk-build places the binary in libs/(arch type) .. For a quick test you can just open a terminal in that directory then:
Code:
adb push mybinary /data/local/tmp/
adb shell
cd data/local/tmp
chmod 777 mybinary
./mybinary
Added:
Examples of basic make files for Android.
happy coding
If you get an errorPlease reissue the command but pipe the output to a file.
make toolbox > /home/droidvoider/Desktop/build_toolbox-output.txt
zip that up with your source code, including your customized header files and attach it to this thread.
puzzles are fun but I like all the pieces
droidvoider said:
Tested up to downloading AOSP and make toolbox -- you should be all set
===>] Match your build number to it's AOSP sources [<===preface: You can get this from your device if you're on the same build id as your the available source code from your vendor for your device. Otherwise you need to open the AP file from the firmware that matches those available sources to extract the system.img, to extract build.prop. I explain how to open a system.img file below under retrieving your hardware drivers. build.prop is in the main directory of system.img
(Many times the build number is the same. For me I believe all of MM builds are using this number.)
Assumes sources match current device, worked out true in my case
1. Plug in your device and get it connected. (DEVELOPER OPTIONS|USB DEBUGGING) and select allow on device
2. Retrieve the build number that matches the available sources for your device.
From your ubuntu terminal retrieve the build id using this command:
Code:
adb shell getprop | grep 'ro.build.id'
Yields something similar to this: [ro.build.id]: [MMB29K]
3. Match it up to the Nexus build numbers (This info is for AT&T Note 5 Marshmallow MMB29K, get your specific build number!)
https://source.android.com/source/build-numbers.html#source-code-tags-and-builds
MMB29K android-6.0.1_r1 Marshmallow Nexus 5, Nexus 5X, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg)
===>] Bring down a specific AOSP source branch [<===
4. Make a directory for the source code.
Code:
mkdir /home/droidvoider/Desktop/AOSP_Android_6.01_r1
5.
Code:
cd /home/droidvoider/Desktop/AOSP_Android_6.01_r1
6. Bring down the sources, this one is approximately 13 gigabytes
Code:
repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r1
repo sync
===>] I'm not sure the rest of this is needed [<===For compiling toolbox the remainder wasn't needed.. But I have a large list of things to do so I can't test each item. If you can't compile a specific module continue reading.
===>] Merge Vendor sources & AOSP sources [<===
7. Download the available sources for your device. In this example I downloaded PE6 Marshmallow sources for AT&T Note 5:
http://opensource.samsung.com/reception/receptionSub.do?method=sub&sub=F&searchValue=SM-N920A
8. Read the readme file from the sources platform zip to understand how to merge them into the AOSP sources. For the 2 Samsungs I've worked with the idea is to replace any directory that already exists. But if there is just one file such as core.mk only replace the one file. Then edit the .mk files as described in your readme. (and/or take info from cyanogen/lineagos) -- <I can help more, ask>
note: you probably don't need to take the configs from LineageOS and put them into your .mk files. However, if you do need to get more configs then you should get a big fat message when you type make 'modulename'. At first only edit .mk files as described by vendor device source readme file.
===>] Merge in Hardware drivers and etc [<===possibly unnecessary depends what you're doing
9. Obtain a copy of the firmware for your device that matches the version of the source code you are able to download from your vendor.
for me that was Build Number: MMB29K.N920AUCU2BPE6 but your mileage will almost certainly vary!
10. Download https://github.com/anestisb/android-simg2img
11. Unzip it right in your download folder, open the folder and then 'open in terminal'
12. Make it and then move it a directory in your path. Warning: My command puts in in the Ubuntu default /bin folder.
Code:
make
sudo mv append2simg img2simg simg2img simg2simg simg_dump.py /bin
13. Uncompress the AP file from the matching firmware and extract the system.img into it's own directory
then select that folder, right click, open in terminal
Code:
simg2img system.img sys.raw
mkdir sys
sudo mount -t ext4 -o loop sys.raw sys/
14. A drive mounted, look on your task bar it should've wiggled too. Copy the etc and vendor folders into the main folder of the sources we are merging
Click to expand...
Click to collapse
And where is exactly the main folder? Sorry, Im just confused
DigitalDoraemon said:
And where is exactly the main folder? Sorry, Im just confused
Click to expand...
Click to collapse
it's no problem this stuff isn't easy to just figure out on your own. remember to substitute droidvoider for your ubuntu user name
In this example my sources are on my desktop in a folder named Android_6.01_r1
Sources for toolbox for example:
/home/droidvoider/Desktop/Android_6.01_r1/system/core/toolbox/<sources will be here including Android.mk>
Script for modules, including toolbox
/home/droidvoider/Desktop/Android_6.01_r1/Makefile <--- this is our modules script, if you will
<open a terminal in the above folder then use that Makefile like so>
make toolbox <---- this will compile only what is needed to compile the module 'toolbox' (this takes a minute)
Out export folder we decided in ./home/droidvoider/bashrc
/home/droidvoider/Android_Build_Out/Android_6.01_r1/target/product/generic/system/bin
Anybody, please compile grep utility for arm and x86... Minimum Platform Version Android 4.0.3, API Level - 15
Thanks
Great & useful .