he good thing about building manually your apk is that you don’t have to name
your resources directory to res, you can name it anything you want.
You
can find ant scripts in:
\platforms\android-1.5\templates\android-rules.xml
Step 1:
Generate Resource java code and packaged Resources
aapt package -f -M
${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library}
-S ${android-resource-directory} [-m -J
${folder.to.output.the.R.java}]
Step 2: Compile java source codes +
R.java
use javac
Step 3: Convert classes to Dalvik bytecodes
use
dx.bat
dx.bat –dex –output=${output.dex.file} ${compiled.classes.directory}
${jar files..}
Step 4: Create unsigned APK
use
apkbuilder
apkbuilder ${output.apk.file} -u -z ${packagedresource.file}
-f ${dex.file}
or
apkbuilder ${output.apk.file} -u -z
${packagedresource.file} -f ${dex.file} -rf ${source.dir} -rj
${libraries.dir}
-rf = resources required for compiled source
files?
-rj = resources required for jar files
Step 6: Generate a
key
use keytool
Step 7: Sign APK
use jarsigner
jarsigner
-keystore ${keystore} -storepass ${keystore.password} -keypass ${keypass}
-signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias}
Step 8:
Publish
use adb
adb -d install -r ${signed.apk}
Inspecting your APK
file:
aapt list -v latest.apk
Dalvik和标准Java虚拟机之间的主要差别?
Dalvik和标准Java虚拟机(JVM)之间的首要差别之一,就是Dalvik基于寄存器,而JVM基于栈。
Dalvik和Java之间的另外一大区别就是运行环境——Dalvik经过优化,允许在有限的内存中同时运行多个虚拟机的实例,并且每一个 Dalvik应用作为一个独立的Linux进程执行。
(1)虚拟机很小,使用的空间也小;
(2)Dalvik没有JIT编译器;
(3)常量池已被修改为只使用32位的索引,以简化解释器;
(4)它使用自己的字节码,而非Java字节码。
@Override public void onClick(View v) {
if( v instanceof Button) {
if(v.getId()=R.id.A) { //这里的A使我们的按钮ID要有 ,这里我做实验随便写的
((Button)v).setText("A按钮 点击了 .");
//添加 ID为A的按钮要实现的代码
}
else if(v.getId()==R.id.B)
{
((Button)v).setText("B按钮 点击了 .");
//添加 ID为B的按钮要实现的代码
}
}
}