android app development
参考:http://developer.android.com/tools/building/index.html
http://wiki.titan2x.com/index.php?title=How_to_build_an_Android_app_project_on_the_command_line_without_Eclipse
http://codeseekah.com/2012/02/09/command-line-android-development-basics/
http://developer.android.com/tools/projects/projects-cmdline.html
http://developer.android.com/tools/building/building-cmdline.html
http://www.cnblogs.com/ifantastic/p/3977672.html
不会android应用程序开发,但是从驱动到内核,再到android中间层,最后到自己提供了一个API,想到了sdk,不得不学习了。
不善于使用集成环境开发应用程序,习惯了自己构建工程,抛弃Eclipse,记录如何使用命令行开发应用。
I)Preparation 1、Download Android SDK from http://developer.android.com/sdk/index.html 2、Install ant from http://ant.apache.org/bindownload.cgi 3、Install Java JAVA_HOME=/usr/local/jdk/jdk1.7 CLASSPATH=${JAVA_HOME}/lib/:${JAVA_HOME}/jre/lib PATH=${JAVA_HOME}/bin:${PATH} //在前,以覆盖系统原来的java链接 //否则可能出现:Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-7-openjdk-i386/lib/tools.jar 4、Setup environment variables (例如ant、javac、android) "ant help" for more details "ant compile" will compile your code and re-generate R.java. "ant debug" will do the above, plus build and sign a package (apk) file. "ant install" will do all of the above plus install it to he emulator/phone (?????) II)Install Android components 1、android update sdk -u -t platform-tool 2、android update sdk -u -t name_of_android_target_platform注:name_of_android_target_platform are named like android-7, for Android API level 7. android update sdk -u -t platform-tool 获得adb等其它调试工具
chown root adb
chmod a+s adb
执行lsusb 获得: Bus 002 Device 004: ID 18d1:deed Google Inc. 在/etc/udev/rules.d/51-android.rules中添加 SUBSYSTEM=="usb", SYSFS{"Google Inc."}=="18d1", MODE="0666" 执行 chmod a+rx /etc/udev/rules.d/51-android.rules /etc/init.d/udev restart /etc/init.d/boot.udev restart adb kill-server adb devices
android list sdk
列出android所有的sdk号
android list targets
列出本机上安装的所有sdk号
注意 AndroidManifest.xml 和 project.properties的由来
III)Build debug APK
ant debug
IV)Build signed release APK
ant release
android create project
start project from stratch on the command line----- run "anroid create project" with "--target", "--name", "--path", "--activity" and "--package" options populated appropriately. android create project \ --target <target_ID> \ --name <your_project_name> \ --path <path_to_your_project> \ --activity <your_activity_name> \ --package <your_package_namespace> example: android create project --target 1 --name MyAndroidApp --path ./MyAndroidAppProject --activity MyAndroidAppActivity --package com.example.myandroid
android update project
android update project --target your_target_id --name your_project_name --path path_to_your_project
参考:http://blog.standalonecode.com/?p=269
http://blog.longwin.com.tw/2010/10/android-hello-world-2010/
下面构建一个helloandroid应用程序
1、android create project --target 2 --name cherry --path ./ --activity cherry --package com.cherry 2、将./src/com/cherry/cherry.java修改为: import android.widget.TextView; super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello Android"); setContentView(tv); //setContentView(R.layout.main); 3、ant release 4、生成keystore;
将bin/cherry-release-unsigned.apk构建成签名jar文件cherry-release-unsigned.apk;
注:如何生成keystore及如何构建jar文件,请参考http://www.cnblogs.com/openix/p/3696656.html
5、zipalign -v 4 bin/cherry-release-unaligned.apk bin/cherry-release.apk 6、android create avd -n JerryTest -t 2 --skin WVGA800 --sdcard 1000M //创建
emulator -avd JerryTest -scale 96dpi -dpi-device 217 -no-boot-anim -wipe-data //启动 7、adb -s emulator-5554 install cherry-release.apk 8、adb -s emulator-5554 shell 'am start -n com.cherry/.cherry' 9、adb -s emulator-5554 uninstall com.cherry 10、android delete avd -n JerryTest