首页 > 其他分享 >Build Android Packages From Command Line

Build Android Packages From Command Line

时间:2022-11-09 23:39:44浏览次数:85  
标签:temp MxDataProvider androidyue Command workspace ubuntu home Android Packages


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

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​


aapt package -f -m -J /home/androidyue/temp/ubuntu/workspace/MxDataProvider/gen/ -S /home/androidyue/temp/ubuntu/workspace/MxDataProvider/res/ -I /home/androidyue/dev_tools/android-sdk-linux_86_backup/platforms/android-17/android.jar -M /home/androidyue/temp/ubuntu/workspace/MxDataProvider/AndroidManifest.xml

Some descriptions

  • -f force overwrite of existing files
  • -m make package directories under location specified by -J
  • -J specify where to output R.java resource constant definitions
  • -S directory in which to find resources. Multiple directories will be scanned and the first match found (left to right) will take precedence.
  • -I add an existing package to base include set
  • -M specify full path to AndroidManifest.xml to include in zip

Comiple .java into .class files



javac -encoding UTF-8 -source 1.6 -target 1.6 -bootclasspath /home/androidyue/dev_tools/android-sdk-linux_86_backup/platforms/android-17/android.jar -d /home/androidyue/temp/ubuntu/workspace/MxDataProvider/bin/ /home/androidyue/temp/ubuntu/workspace/MxDataProvider/src//coop/channel/provider/*.java /home/androidyue/temp/ubuntu/workspace/MxDataProvider/gen//coop/channel/provider/R.java

Some descriptions

  • -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

Convert .class into .dex files


/home/androidyue/dev_tools/android-sdk-linux_86_backup/build-tools/17.0.0/dx --dex --output=/home/androidyue/temp/ubuntu/workspace/MxDataProvider/bin//class.dex /home/androidyue/temp/ubuntu/workspace/MxDataProvider/bin/

To dive into Dalvik, please visit ​​http://source.android.com/devices/tech/dalvik/index.html​

Package Resouces



aapt package -f -M /home/androidyue/temp/ubuntu/workspace/MxDataProvider/AndroidManifest.xml -S /home/androidyue/temp/ubuntu/workspace/MxDataProvider/res/ -A /home/androidyue/temp/ubuntu/workspace/MxDataProvider//assets/ -I /home/androidyue/dev_tools/android-sdk-linux_86_backup/platforms/android-17/android.jar -F /home/androidyue/temp/ubuntu/workspace/MxDataProvider/bin//resources.ap_

Some descriptions

  • -F specify the apk file to output
  • -A additional directory in which to find raw asset files

Build Unsigned APK File


/home/androidyue/temp/ubuntu/dev_tools/adt-bundle-linux_backup/sdk/tools/apkbuilder /tmp/unsignedApkFile.apk -v -u -z /home/androidyue/temp/ubuntu/workspace/MxDataProvider/bin//resources.ap_ -f /home/androidyue/temp/ubuntu/workspace/MxDataProvider/bin//class.dex -rf /home/androidyue/temp/ubuntu/workspace/MxDataProvider/src/

Some descriptions

  • -u Creates an unsigned package.
  • -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.

Sign Apk with Jarsigner



jarsigner -keystore /home/androidyue/temp/ubuntu/myKeystore -storepass storepassValue -keypass keypassValue -signedjar /home/androidyue/Desktop/output/max1111111.apk /tmp/unsignedApkFile.apk maxthon -digestalg SHA1 -sigalg MD5withRSA

Some descriptions

  • [-keystore ] keystore location
  • [-storepass ] password for keystore integrity
  • [-keypass ] password for private key (if different)
  • [-signedjar ] name of signed JAR file
  • [-digestalg ] name of digest algorithm
  • [-sigalg ] name of signature algorithm

Use Zipalign for optimization



zipalign -f -v 4 /home/androidyue/Desktop/output/max1111111.apk /home/androidyue/Desktop/output/max222222.apk

Some descriptions

Others

  • How to Build an Android: The True Story of Philip K. Dick’s Robotic Resurrection


标签:temp,MxDataProvider,androidyue,Command,workspace,ubuntu,home,Android,Packages
From: https://blog.51cto.com/u_3987305/5838962

相关文章

  • 为Android程序申请权限注意
    Android系统提供为程序提供了权限申请,即在manifest中使用uses-permission来申请即可.实现起来非常简单,但是有些问题会随之浮出水面.常见的现象是,有时候新加一个权限,(在......
  • Start an Android App by ADB
    Tobemoregeek,IbegantostartanAndroidAppbyusingadb.ThankstoGoogle.It’spossibleandpowerful.ThetoolweusetomakeitisADB(AndroidDebugTool)......
  • Android内存泄漏:谨慎使用getSystemService
    Android中有很多服务,比如PowerManager,AlarmManager,NotificationManager等,通常使用起来也很方便,就是使用Context.getSystemService方法来获得。一次在公司开发项目开发中,突......
  • 记一场 Android 技术答疑
    之前在Stuq的Android课程中有幸分享了一些关于优化的问题,后期又处理了一些来自网友的问题,这里简单以文字形式做个整理.网络IO应该在哪种形式的线程中执行首先网络IO一般耗......
  • 在 Android 中如何确定 App(Activity) 的启动者
    最近在帮忙定位一个问题,涉及到某个应用自动启动了,为了确定是谁调用的,使用如下的日志进行查看(注:为了简单考虑,下面的启动者为launcher)(pre_release|✔)%adblogcat|grep......
  • Android WebView 诊断与排查问题的方法和技巧
    WebView,是安卓中很重要的一个组件,我们的应用中集成WebView后,可能会遇到各种各样的问题,这里简单介绍一些AndroidWebView诊断与排查问题的方法,希望对于大家有这方面的问题的......
  • Android开发 Ripple涟漪效果
    前言此博客讲解Android5.0版本之后的涟漪效果的使用 简单的使用例子ripple_ic_bg.xml<?xmlversion="1.0"encoding="utf-8"?><ripplexmlns:android="http://......
  • android studio 升级 Android Studio Dolphin | 2021.3.1 Patch 1
    androidstudio升级AndroidStudioDolphin|2021.3.1Patch1后,xml布局预览界面报错一开始以为是那些警告导致的,有很多黄色的xml警告,比如命名的名字不是英文,或者设置......
  • 直播平台怎么搭建,Android与Js互调之传递图片
    直播平台怎么搭建,Android与Js互调之传递图片添加addJavascriptInterface注解方法H5VerificationJavascriptInterface对象映射 publicclassH5VerificationJavascrip......
  • 深入剖析Android应用开发--视频
    ​​深入剖析Android应用开发​​​​http://v.51work6.com/courseInfoRedirect.do?action=courseInfo&courseId=240568​​Android作为一款为移动终端打造的开源手机操作平......