Python provides a lot of method to read output from a just executed shell. However many of them has been deprecated(Not recommened). But subprocess works at present compared to other methods.
A few months ago,I dealed with a task:To build a large amount of apk files. The trick I came up with is to build apk file from the command so that I could use Python to glue all the works. Eventually I made it.And so this post is to make some description about the trick.
##Requirements
Setup JDK
Setup Android SDK
##Steps
Generate R class file
Compile Java codes(.java files) into classes(.class) files
Convert .class files into .dex files
Package Resouces
Build Unsigned APK File
Sign Apk with Jarsigner
The Extra One:Use zipalign for optimization
###Generate R class File
In Android,We use R class to refer resources instead of hard-coding the resouces.
For a better understanding,pleae have a look at http://www.satyakomatineni.com/akc/display?url=displaynoteimpurl&ownerUserId=satya&reportId=2883
-encoding encoding Set the source file encoding name, such as EUC-JP and UTF-8. If -encoding is not specified, the platform default converter is used.
-source release Specifies the version of source code accepted, Please Do NOT use Java 7(1.7)
-target version Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. Valid targets are 1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6(also 6), and 1.7 (also 7).
-bootclasspath bootclasspath Cross-compile against the specified set of boot classes. As with the user class path, boot class path entries are separated by colons (:) and can be directories, JAR archives, or ZIP archives.
-d directory Set the destination directory for class files. The directory must already exist; javac will not create it.
As I have suffered a lot using Java 7, It’s recomended to use Java 6
-z Followed by the path to a zip archive. Adds the content of the application package.
-f Followed by the path to a file. Adds the file to the application package.
-rf Followed by the path to a source folder. Adds the java resources found in that folder to the application package, while keeping their path relative to the source folder.
The is an integer that defines the byte-alignment boundaries. This must always be 4 (which provides 32-bit alignment) or else it effectively does nothing.
For more details, please visit http://developer.android.com/tools/help/zipalign.html
To be more geek,I began to start an Android App by using adb.Thanks to Google.It’s possible and powerful.
The tool we use to make it is ADB(Android Debug Tool),For more detailed use please visit http://developer.android.com/tools/help/adb.html#shellcommands
Actually What I use here is
1
start [options] <INTENT>
An example is followed.
1234
#Here I want to start MxBrowser app by using ADB17:04:30-androidyue/tmp$ adb shell am start -n com.mx.browser/com.mx.browser.MxBrowserActivity
Starting: Intent {cmp=com.mx.browser/.MxBrowserActivity }Warning: Activity not started, its current task has been brought to the front
the Package name(com.mx.browser) before the slash is provided to determine which app should the intent delivered to.The com.mx.browser.MxBrowserActivity is the destination Activity.
For more explanations about ADB INTENT,please visit http://developer.android.com/tools/help/adb.html#IntentSpec
An easy trick to solve problem:Could not reliably determine the server’s fully qualified domain name
Let’s take Linux for example.
12
#Modify your configuration file.12:52:21-androidyue/etc/httpd/conf$ sudo vim httpd.conf
Find out the following sentence
12345678910111213
## ServerName gives the name and port that the server uses to identify itself.# This can often be determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## If this is not set to valid DNS name for your host, server-generated# redirections will not work. See also the UseCanonicalName directive.## If your host doesn't have a registered DNS name, enter its IP address here.# You will have to access it by its address anyway, and this will make # redirections work in a sensible way.##ServerName localhost:80
If the ServerName localhost:80 has been commented,it may cause above problem.A simple trick is just uncomment the sentence.Let it be like this
Recently I have been dealing with files and I need to get md5 hash of all kinds of files;Some are small and some are big.
For the small files I use this method to get md5 hash value.
However for calculating md5 hash value of big files,the above method will be very Less Efficient.For Big files I use the following method(It’s acquired from stackoverflow)
I was once stucked in installing build-essentials which is for Debian/Ubuntu.I could not find any packages like build-essentials in yum.However this helped me out.
I have been getting well on with my java tool.However When I use the javac command.It says
1
javac : command not found
It’s just because I just only install the JRE(Java Runtime Environment) and do not install JDK(Java Development KIt).I got the answer going for my fedora
I have often suffered this painful thing.When I start a service but the destination port is always used.So I should list all open ports and kill the occupied application.
So This is a short tip for how to list open ports on Linux
1
sudo netstat -tulpn
Note sometimes you should grant the command for a enough access.
For a better understanding,please
1
man netstat
or navigate to http://linux.about.com/od/commands/l/blcmdl8_netstat.htm
Yum is a great tool for manage dependencies and easy to use.However actually there is a way to speed up the installation.
Fastestmirror is a tool that will help yum determin what mirror is fastest and to use.
To install on Fedora 17
1
sudo yum install yum-fastestmirror
Of course you could customize the fastestmirror configuration easily
1
sudo vim /etc/yum/pluginconf.d/fastestmirror.conf
So when you next install a package from the network,I hope you could feel it much faster.
I once had a request to sum the number of files in a specific folder.After googling I found the command wc could help me out.
wc - print newline, word, and byte counts for each file. And I think wc is short for Word Count.Please have a detailed information by visiting http://linux.about.com/library/cmd/blcmdl1_wc.htm if you have the desire.
Ok,Let’ get the total number of files(including folders) in a specific folder
1
20:56:08-androidyue/tmp$ ls | wc
Well,the following command will sum the number of pure files(Not including folders)
1
20:58:27-androidyue/tmp$ ll | grep ^- | wc
However how to sum the number of pure folder?The following command will help.
Git-daemon is A really simple server for git repositories.You can take a detailed understanding by reading https://www.kernel.org/pub/software/scm/git/docs/git-daemon.html .
I once often used git-daemon when I was using Ubuntu.But when I turn to Fedora and found it was not installed.And the output is like the following.
1
git: 'daemon' is not a git command. See 'git --help'.
So I write this post to record How to install and enable git-daemon
First Let’s intall the git Daemon:
1
sudo yum install git-daemon
However git daemon is off by default.We should enable it.We should do as the following.
1
vim /etc/xinetd.d/git
And modify the file as the following configuration.
# default: off
# description: The git dæmon allows git repositories to be exported using
# the git:// protocol.
service git
{
disable = no
socket_type = stream
wait = no
user = nobody
server = /usr/libexec/git-core/git-daemon
server_args = --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose
log_on_failure += USERID
# xinetd does not enable IPv6 by default
flags = IPv6
}
And then,We use this command to start the git Daemon
Mostly we could clone the repositories from the git daemon.
But if you have enabled Firewall and other people want to clone the repository from your git daemon,please let the port 9418 available to the outsite.
Is there any way to append output(debugging information) to a existings file? As we all know in bash the command ‘>’ will write ouputs to a file.However this command will also erase the existing data it the file.
Of course bash provides a command that appends outputs to a file.It resembles ‘>’.It’s ‘»‘
The following is a piece of example code.
#####Let’s look at >
Actually I am fresh to Write Blog with Octopress in Github Pages.According to the Introduction .And now I have make it avaible and the website is present.
However I have suffered some problems when I did the setup.Here is a summary of what I have sufferd and how I resolved.
Could not find rdiscount-2.0.7.3 in any of the sources Run bundle install to install missing gems.
[androidyue@androidyue octopress]$ rake preview
Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
[2013-09-07 15:46:20] INFO WEBrick 1.3.1
[2013-09-07 15:46:20] INFO ruby 1.9.3 (2013-06-27) [i686-linux]
[2013-09-07 15:46:20] INFO WEBrick::HTTPServer#start: pid=10490 port=4000
Configuration from /home/androidyue/github/octopress/_config.yml
Auto-regenerating enabled: source -> public/
[2013-09-07 15:46:21] regeneration: 95 files changed
>>> Change detected at 15:46:21 to: screen.scss
create public/github/stylesheets/screen.css
Errno::ENOENT on line ["56"] of /home/androidyue/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/actions.rb: No such file or directory - /home/androidyue/github/octopress/public/github/stylesheets/screen.css
Run with --trace to see the full backtrace]
As the above information and all the sources are outputed in public/ folder And the following are a part of my _config.yml file
# If publishing to a subdirectory as in http://site.com/project set 'root: /project'
root: /
permalink: /blog/:year/:month/:day/:title/
source: source
destination: public/
plugins: plugins
code_dir: downloads/code
category_dir: blog/categories