[Android]命令行编译APK

(2010年04月18日) 发表于 ChinaUnix

手动编译你的apk,可以让资源目录不命名为res, 你能够命名任何你想要的名字。

你可以在以下目录发现ant脚本: <SDK_HOME>\platforms\android-1.5\templates\android-rules.xml

第一步: 产生R文件以及包资源
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}]


第二步:编译java源文件以及R.java文件
use javac


第三步:将classes文件转化成Dalvik自节码
use dx.bat
dx.bat –dex –output=${output.dex.file} ${compiled.classes.directory} ${jar files..}

第四步:创建未签名的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

第六步: 产生一个key
use keytool

第七步骤: 对APK进行签名
use jarsigner

jarsigner -keystore ${keystore} -storepass ${keystore.password} -keypass ${keypass} -signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias}


第八步: 发布
use adb
adb -d install -r ${signed.apk}

Inspecting your APK file:

aapt list -v latest.apk

Open questions:
1. Can you include more than one dex file in the apk?
2. Can you have dex file named other than classes.dex in the apk?
3. Does an apk have to have a packaged resource?

转自:

http://itnewsvendor.appspot.com/447063-android_%E5%91%BD%E4%BB%A4_%E7%BC%96%E8%AF%91.html

android 打包第三方jar包

Add a comment 1,362 views June 30th, 2011 Charlie android, android 打包外部jar文件 android 打包外部包, android 打包第三方jar

android项目开发时会用到第三方提供的jar包,通常情况下按照eclipse导入jar包的方法(选择项目,右键点击Build Path,Build Path–>Add Libraries–>User Library–>Next–>User Libraries–>New–>Add JARs,选择第三方的jar包),就可以将jar包导入到项目。

根据这样的打包方式时,eclipse导入jar包后,eclipse编译器也能识别,即项目不会因为缺少jar包而报错,但是运行android程序的时候却没有找到包而报错了。APK文件也很小,也就是jar包并没有打包到APK文件中。

在android项目中找到.classpath文件并打开,文件代码如下:

view plain copy to clipboard print ?
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <classpath>
  3. <classpathentrykind="src"path="src"/>
  4. <classpathentrykind="src"path="gen"/>
  5. <classpathentrykind="con"path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
  6. <classpathentrykind="con"path="org.eclipse.jdt.USER_LIBRARY/box2d"/>
  7. <classpathentrykind="output"path="bin"/>
  8. </classpath>

发现eclipse导入包操作后,写入了这行代码

<classpathentry kind=”con” path=”org.eclipse.jdt.USER_LIBRARY/box2d”/>

这行代码应该是eclipse内部识别的,并不会打包到模拟器上,所以运行到模拟器上找不到相应的jar包。

为了在android内部能找到jar包,于是在android项目内新建一个lib文件夹,将jar包放在lib文件夹内。
并将上面的那行代码删除,添加一行代码:

<classpathentry kind=”lib” path=”lib/jbox2d-2.0.1-full.jar”/>

jbox2d-2.0.1-full.jar是lib文件下的jar包,可添加多个jar包。

即最终修改代码为:

view plain copy to clipboard print ?
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <classpath>
  3. <classpathentrykind="src"path="src"/>
  4. <classpathentrykind="src"path="gen"/>
  5. <classpathentrykind="con"path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
  6. <classpathentrykind="lib"path="lib/jbox2d-2.0.1-full.jar"/>
  7. <classpathentrykind="output"path="bin"/>
  8. </classpath>

最后刷新eclipse项目,会发现项目bin目录的APK文件大小增大,说明APK文件已经包含jar包文件,重新clean项目并运行即可。

转自:http://www.yoyong.com/archives/254


查词典 Dict.cn海词-划词释义 已开启划词 设置

更多相关文章

  1. 实现TextView的垂直滚动以及通过代码设置TextView滚动无法显示滚
  2. android操作sdcard中的多媒体文件(二)——音乐列表的更新
  3. Android Studio使用XML样式在JAVA代码中的使用(使用java代码调节x
  4. Android实现代码画虚线边框背景效果
  5. Android显示GIF动画---------Android开源项目:GifView的使用
  6. 重温android studio jni编译生成so文件
  7. Android 笔记:读取配置文件config.properties

随机推荐

  1. C#中算法的实例详解
  2. C# 并行任务之Parallel类的实例介绍
  3. 关于操作 ASP.NET Web API的实例
  4. VS2015常用快捷键详解
  5. wcf什么意思?关于wcf的实例教程
  6. Visual Studio 中自定义生成事件的详细介
  7. 值类型对象的两种表示形式
  8. net 使用 data.oracleclient 出现的错误
  9. 经典的IoC/DI容器--StructureMap
  10. 最新版近乎v5.0新型社区发布介绍