Use ant to compile the signature.
Signature problems with ant Compilation
DionysosLai (906391500@qq.com)
Using ant compilation can greatly improve project development efficiency. Currently, coco2dx uses ant technology to accelerate compilation by dozens of times. The principle is to compile the engine library into an so file in advance. During Game compilation, you only need to compile your own code without compiling the engine code at the same time. Compared with your own code and engine code, the difference between the two is dozens of times, so the speed will increase a lot. On the other hand, there are many problems. In Eclipse, only errors are reported, but the specific location cannot be pointed out (I believe this problem occurs when you write the mk file ). However, if ant compilation is used, the specific location of the problem is displayed completely.
Of course, it is also difficult to use ant to compile the code, that is, the code will be re-compiled every time, instead of the changed code. As a result, it takes one to two minutes to generate an apk file each time, this depends on the amount of game code.
In the cocos2dx engine, using ant to compile the project is a complicated operation. Therefore, we plan to divide it into several parts and clarify the problem in detail. As the first article about ant compilation, I will first discuss a simple topic: Signature. The extension of this topic is to automatically generate an apk and sign it.
There are two types of apk Signature: manual signature and automatic signature.
Manual signature:
1. Generate apk
Use ant to compile the signature problem using ant to compile, you can refer to this PDF file (http://download.csdn.net/detail/dionysos_lai/8333741) or other online materials. The command is similar to the following:
Call cd project Folder \ proj. androidcallandroid update project-p. call antcleancall antdebugpause
This is an automatic compilation script I wrote. Double-click it to run it. This will automatically generate a debug apk (Note: The debgu apk will automatically add the bebug signature to the apk, only
"Call ant debug" is changed to "call ant release" to generate an unsigned release apk ).
2. Apk Signature
For more information about how to sign an Apk, see the script command line I wrote here:
Call jarsigner-verbose-keystore key file name-signedjarok/generate apk name on behalf of signature apk name key file name pause
Create. bat file, put the file in the directory at the same level as the apk to be signed, double-click to run, and enter the password of the signature key file, and the signed apk will be generated in the OK folder.
There is a problem with the signature: "java.util.zip. ZipException: invalid entry compressed size (expected 4308 but got 4432 bytes )". Many people have encountered this problem on the internet, and I have also encountered this problem during ant compilation. There are many online statements, and the same can be solved. Later, the analysis problem was actually very simple, that is to say, the apk size error should have been 4308 bytes. Now it is 4432 bytes, and the compression error is reported. In fact, this problem occurs because we tried to use the debug apk signature, and the debug apk has already been signed (this is also the reason why the apk size increases ). Therefore, we can only output the release apk and re-sign it.
Directly change "call ant debug" to "call ant release". Double-click the script file and the following error will be reported;
(Ps, This is the benefit of ant compilation and the location of the problem is clear.) This is because the 67 lines of the file "custom_rules.xml" clearly write "<copyfile =" $ {source. absolute. dir }/.. /bin/${ant.project.nameapps-debug.apk "tofile =" $ {customapk. out}/registrant.project.name).apk "/>" you just need to change it to this. "<copy file =" $ {source. absolute. dir }/.. /bin/${ant.project.name+-release.apk "tofile =" $ {customapk. out}/registrant.project.name).apk "/>"
3. Verify the signature
For Apk signature verification, use the following command line. For more information, see:Http://stackoverflow.com/questions/7104624/how-do-i-verify-that-an-android-apk-is-signed-with-a-release-certificate/7104680#7104680
Calljarsigner-verify-verbose-certs apk name to be verified
Automatic Signature:
Compared with manual signatures, automatic signatures can save the step of manually adding a signature to the apk. However, automatic signatures can only be for the release version, while the debug version does not.
How to automatically sign the signature is actually detailed in the file "ant. properties:
# This file is used to override default values used bythe Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# Integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such
# 'Source. dir' forthe location of your java source folder and
# 'Out. dir' forthe location of your output folder.
# You can also use it define how the release builds aresigned by declaring
# The following properties:
# 'Key. store' forthe location of yourKeystoreAnd
# 'Key. alias' forthe name of the key to use.
# The password will be askedduring the build when you use the 'release' target.
Add the following statements to the file as prompted:
key.store=E:/LogicGame/cocos2d-x-2.2.3/apk/keykey.alias=keykey.store.password=123456key.alias.password=123456
Note that "key" is the signature key, 123456, And the password. There may be such an error.
The cause of this error is the format problem of unix and window, that is, "/", wrong "\".
OK. The ant signature is almost here. I hope it will be useful to you.