How to package Android source code into APK

Source: Internet
Author: User
Tags echo message

Note: newnetclient is the source code directory name,

Current environment variable settings: JDK, Android SDK, and OpenSSL environment variables.

Required package files: Android. jar, signapk. jar.

Javac C:/APK/Hello/*. Java-classpath C:/testapk/Android. jar-d c:/APK/classes

@ REM: regenerates the R. Java file automatically, for example, adding an image or string or adding an XML file in the layout directory.
C:/users/Dell> aapt package-m-j c:/APK/newnetclient/Gen-m c:/APK/newnetclient/androidmanifest. XML-s c:/APK/newnetclient/RES-I c:/APK/android. jar

@ REM: regenerates the R. Java file automatically, for example, adding an image or string or adding an XML file in the layout directory.
Aapt package-m-J Src-m c:/APK/newnetclient/androidmanifest. XML-s c:/APK/newnetclient/RES-I c:/APK/Android. Jar

@ REM compile the Java file including R. Java and output it to C:/APK/classes.
C:/users/Dell> javac C:/APK/Hello/src/Android/Hello/*. Java C:/APK/Hello/GEN/Andro
ID/Hello/*. Java-classpath C:/testapk/Android. jar-d c:/APK/classes

@ REM package the *. Class file in the Directory into a jar package. In order to create the classes. Dex file required by the APK later (the generated file is in the current directory *. * Relative Path)
C:/APK/classes> jar cvf ffff. jar *.*

@ REM: Convert the jar package to the DEX file that can be run by the Android mobile phone.
C:/APK/classes> DX -- Dex -- output = classes. Dex C:/APK/classes/FFFF. Jar

@ REM Delete the object if it exists.
If exist fffnew3.apk .(
Del fffnew3.apk.
Echo message AB
) Else (
Echo fffnew3.apk. Missing.
Echo message AB C

@ REM generate application APK file ffffqc.apk
C:/APK/classes> aapt package-z-u-F-m c:/APK/Hello/androidmanifest. XML-s c:/APK/Hello/RES-I c:/testapk/android. jar-f c:/ffffqc.apk

@ REM: compress the classes. Dex file generated earlier to the APK file to generate a running APK application.
C:/APK/classes> aapt add C:/ffffqc.apk classes. Dex

@ REM Method 1: automatically sign the generated APK. An unsigned APK cannot be installed.
C:/testapk> JAVA-jar signapk. Jar aimoxiu. x509.pem aimoxiu. pk8 C:/APK/classes/fffnew3.apk fffnew3last.apk
"C:/program files/Java/jre6/bin/jarsigner"-verbose-keystore "D:/apksign/myand. keystore "-signedjar % 1% 2" D:/apksign/myand. keystore"

@ REM Private Key Generation Method
@ REM generate RSA private key)
OpenSSL genrsa-3-out testkey. pem 2048
@ REM generates an authentication request in PKCS #10 format. An authentication request is a request sent to the certification authority. It mainly includes a public key and related information (such as the organization name and contact email address ).
OpenSSL req-New-X509-key testkey. PEM-out testkey. x509.pem-days 10000/-subj '/C = US/ST = California/L = Mountain View/o = Android/ou = Android/CN = Android/emailaddress ='
@ REM converts the private key format to PKCS #8 (private-key information syntax standard .)
OpenSSL pkcs8-In testkey. pem-topk8-outform der-out testkey. pk8-nocrypt

Its usage is as follows:
Usage: signapk publickey. X509 [. pem] privatekey. pk8 input. Jar output. Jar
The first parameter is the public key, that is, testkey. x509.pem generated in the previous step.
The second parameter is the private key, that is, testkey. pk8 generated in step 3.
The third parameter is the file to be signed.
The fourth parameter is the output file (the signed file ).
Example: Java-jar signapk. Jar testkey. x509.pem testkey. pk8

@ REM Method 2: keytool generates myandf. keystore signature jarsigner generates the signed APK File
Keytool-genkey-alias myandf. keystore-keyalg RSA-validity 20000-keystore myandf. keystore
Jarsigner-verbose-keystore myandf. keystore-signedjar fffnew3last.apk fffnew3.apk myandf. keystore (password 123456 1234567)

Start packaging:
Javac C:/users/Dell> javac C:/APK/newnetclient/GEN/COM/palmdream/newnetclient /*. java C:/APK/newnetclient/src/COM/palmdream/CORE /*. java C:/APK/newnetclient/src/COM/palmdream/listholder /*. java C:/APK/newnetclient/src/COM/palmdream/netengine /*. java C:/APK/newnetclient/src/COM/palmdream/newnetclient /*. java C:/APK/newnetclient/src/COM/palmdream/xmldata /*. java C:/APK/newnetclient/src/org/kxml2/IO /*. java C:/APK/newnetclient/src/org/xmlpull/V1 /*. java-classpath C:/APK/android. jar-d c:/APK/classes
Echo javac is OK
C:/APK/classes> jar CVF fffnew3.jar COM/*. * ORG /*.*
Echo jar CVF is OK
C:/APK/classes> DX -- Dex -- output = C:/APK/classes. Dex C:/APK/classes/fffnew3.jar
Echo DX -- Dex OK
C:/APK/classes> aapt package-z-u-F-m c:/APK/newnetclient/androidmanifest. XML-s c:/APK/newnetclient/RES-I c:/APK/android. jar-f c:/fffnew3.apk
Echo aapt package OK
C:/APK/classes> aapt add C:/fffnew3.apk classes. Dex
Echo aapt add OK
C:/testapk> JAVA-jar signapk. Jar aimoxiu. x509.pem aimoxiu. pk8 fffnew3.apk fffnew3last.apk
Echo Java last OK

@ REM multi-thread control start stop start new threads and transfer headers when the network is connected.
@ REM Android-based code protection

Add comments

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.