关闭

android开发---使用ant编译android项目

871人阅读 评论(0) 收藏 举报
分类:

http://blog.chinaunix.net/uid-26009923-id-3430864.html

 

eclipse太难用了,幸好android支持ant来编译工程,纯手工打造,下面以hello-jni为例来试验一下。

  1. sun@ubuntu:/tmp/project/hello-jni$ ls
  2. AndroidManifest.xml default.properties jni res src tests
  3. sun@ubuntu:/tmp/project/hello-jni$ android list target  ;列出支持的target
    Available Android targets:
    ----------
    id: 1 or "android-11"
         Name: Android 3.0
         Type: Platform
         API level: 11
         Revision: 2
         Skins: WXGA (default)
         ABIs : armeabi
    ----------
    id: 2 or "Google Inc.:Google APIs:11"
         Name: Google APIs
         Type: Add-On
         Vendor: Google Inc.
         Revision: 1
         Description: Android + Google APIs
         Based on Android 3.0 (API level 11)
         Libraries:
          * com.google.android.maps (maps.jar)
              API for Google Maps
         Skins: WXGA (default)
         ABIs : armeabi

  4. sun@ubuntu:/tmp/project/hello-jni$ android update project -p . -t android-11
  5. Updated and renamed default.properties to project.properties
  6. Updated local.properties
  7. No project name specified, using Activity name 'HelloJni'.
  8. If you wish to change it, edit the first line of build.xml.
  9. Added file ./build.xml
  10. Added file ./proguard-project.txt
  11. It seems that there are sub-projects. If you want to update them
  12. please use the --subprojects parameter.
  13. sun@ubuntu:/tmp/project/hello-jni$ ant debug
  14. Buildfile: /tmp/project/hello-jni/build.xml
  15. BUILD SUCCESSFUL
  16. Total time: 4 seconds

1. 只需要两步就搞定了,不过这个是没有签名的。 说明: 
a. android update project -p <project> -t <target>
    -t 后的参数<target> 可以用 android list target查看
   执行后会生成build.xml
b. 用 ant debug -->编译工具自动签名debug key和使用zipalign优化打包
   用 ant release -->需要自己签名和优化
2. 进行手动签名

  1. sun@ubuntu:/tmp/project/hello-jni$ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
  2. Enter keystore password: 
  3. Re-enter new password: 
  4. What is your first and last name?
  5.   [Unknown]: name
  6. What is the name of your organizational unit?
  7.   [Unknown]: unit
  8. What is the name of your organization?
  9.   [Unknown]: org
  10. What is the name of your City or Locality?
  11.   [Unknown]: ciyt
  12. What is the name of your State or Province?
  13.   [Unknown]: state
  14. What is the two-letter country code for this unit?
  15.   [Unknown]: 123
  16. Is CN=name, OU=unit, O=org, L=ciyt, ST=state, C=123 correct?
  17.   [no]: yes

  18. Generating 2,048 bit RSA key pair and self-signed certificate (SHA1withRSA) with a validity of 10,000 days
  19.     for: CN=name, OU=unit, O=org, L=ciyt, ST=state, C=123
  20. Enter key password for <alias_name>
  21.     (RETURN if same as keystore password): 
  22. [Storing my-release-key.keystore]
  23. sun@ubuntu:/tmp/project/hello-jni$ jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore my-release-key.keystore ./bin/HelloJni-release-unsigned.apk  alias_name
    Enter Passphrase for keystore: 
       adding: META-INF/MANIFEST.MF
       adding: META-INF/ALIAS_NA.SF
       adding: META-INF/ALIAS_NA.RSA
      signing: AndroidManifest.xml
      signing: resources.arsc
      signing: classes.dex
    sun@ubuntu:/tmp/project/hello-jni$ adb install ./bin/HelloJni-release-unsigned.apk
    87 KB/s (4877 bytes in 0.054s)
        pkg: /data/local/tmp/HelloJni-release-unsigned.apk
    Success

3. 自动签名,这项技术我还没有掌握
[参]http://www.2cto.com/kf/201207/139909.html

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:731229次
    • 积分:6920
    • 等级:
    • 排名:第3438名
    • 原创:22篇
    • 转载:325篇
    • 译文:8篇
    • 评论:49条
    文章分类
    最新评论