Organize the Unity Export Android project using Ant for Multi-channel batch packaging APK

Source: Internet
Author: User

Unity-derived Android works with Ant for multi-channel cycle batch Packaging

One: Set the Java environment variable

Do Android Development Configuration this is the foundation.

Configure the Java environment variable under Win7, here is the link

Http://www.cnblogs.com/zhj5chengfeng/archive/2013/01/01/2841253.html

II: Configure the SDK environment variables for Android

In addition to the need for Java environment variables, we also need to configure the location of the Android SDK, the name is Android_home, the value is the location of your Android SDK, such as mine, as shown below:

Two: Install Ant and set ant environment variables

1. Download the latest ant package on the ant website (http://ant.apache.org/bindownload.cgi) in http://sourceforge.net/projects/ant-contrib/ Files Download Ant expansion pack Ant-contrib-1.0b3.jar (this package is for looping through multiple channel packages).

2. Extract the ant package to the common development tools directory (choose it yourself, I put it in the D:/dev directory), and then copy the downloaded Ant expansion pack ant-contrilb to the Lib folder in the Ant installation directory.

3. Set the ANT environment variable: ant_home, the variable value points to the ant directory.

4, increase in the environment variable path:%ant_home%/bin;%ant_home%/lib;

5, set up after the verification. Open cmd Input ant-version command The following feedback indicates that the ant installation was successful

Third, configure the packaging project

Unity Export Android project in

Export the project file directory as follows:

Import into eclipse

Add a label to identify the channel under the Application tab in Androidmainfest.xml

If there is a problem and the error pops up after the change, please select quick fix

1. Generate Build.xml File

Open cmd and go to C:\USERS\ADMINISTRATOR\DESKTOP\TEST\4\COM.GAME.QQ under this project directory using Android update project-n com.game.qq-p. Command ( Note-N represents the name of the project, and a dot after the-p parameter indicates the current directory, and a dot (.) follows-P.

Note: If it is a unity-packed Android project, the name added after-N must match the name in the Playersetting-bundleidentifier in unity

After this command is executed, the Build.xml and local.properties files are automatically generated in the project.

Edit Build.xml File


<!--value is followed by the project's path--
<name= "Out.unaligned.dir"
value= "C:/users/administrator/desktop/sdk/share/wca landlord"/><mkdirdir= "${out.unaligned.dir}" />    <Targetname= "Modify_update_file">        <Echo>Make Channel ${channel}</Echo>                <Replaceregexpfile= "Androidmanifest.xml"Match= ' Channel 'Replace= ' ${channel} 'byline= "false"encoding= "Utf-8"        />        < Propertyname= "Out.unaligned.file" Location= "${out.unaligned.dir}/wca_${channel}.apk"/>            </Target>    <Targetname= "Make_one_channels"depends= "Savemanifest,modify_update_file,release,replacemanifest,deletebin"Description= "description">    </Target>    <Targetname= "Replacemanifest">        <Echo>Replacemanifest</Echo>        <Deletefile= "${basedir}\androidmanifest.xml"/>        <Copyfile=".. \temp\build\meta-inf\androidmanifest.xml "Todir= "${basedir}"encoding= "Utf-8"/>    </Target>    <Targetname= "Savemanifest">        <Echo>Savemanifest</Echo>        <Copyfile= "${basedir}\androidmanifest.xml"Todir=".. \temp\build\meta-inf "encoding= "Utf-8" />    </Target>    <Targetname= "Deletebin">        <Deletedir= "${basedir}\bin" />    </Target>        <!--classpath is the ant path . -    <Taskdefname= "foreach"ClassName= "Net.sf.antcontrib.logic.ForEach"Classpath= "D:/androidsdk/tools/lib/ant-contrib-1.0b3.jar" />    <Targetname= "Make_channels">        <foreachTarget= "Make_one_channels"List= "${market_channels}"delimiter=","param= "Channel">        </foreach>    </Target>

You also need to create ant.properties manually

The contents are as follows:

key.store=c:/users/administrator/desktop/test/4/com.game.qq/com.game.qq.keystorekey.alias= beijingkey.store.password=123456key.alias.password=123456market_channels=wca,qq,360,91

2, if the project introduced a third-party engineering library, such as my project, the introduction of three third-party projects:

If you execute the package command, you will get an error, because the library does not support ant Auto-compiling, and we need to let it be supported first (note: Third-party projects are set to Lib:project->properties->android-> Library->is Library this tick). Go to the directory where the Library project is located, enter the command Android update lib-project-p./(note is lib-project);

The process of packaging:

(1) The target of line 36th Make_channels is the ant's entry, which uses a foreach loop to call Target (line 17th) named Make_one_channels and market_ Replace each value in the channels collection with the channel

(2) The Make_one_channels target specifies the process for each package:

Savemanifest: Before packaging, copy the original androidmanifest.xml to the same level directory under the project under the temp under Build Meta-inf

Modify_update_file: Matches the channel in the Androidmanifest.xml and replaces it

Release: Automatic compilation plus signature

Replacemanifest: Delete androidmanifest.xml, copy the original androidmanifest.xml from Temp/build/meta-inf back to the project root

Deletebin: Delete bin file ( Note : This step is important, otherwise you can only play a channel apk, when doing this piece of the problem encountered)

Use of the packaging method

Open cmd terminal, execute CD C:\USERS\ADMINISTRATOR\DESKTOP\TEST\4\COM.GAME.QQ

Note Before running to pay attention to clean the project, or may report errors, remember!!!!

Need to execute ant clean in cmd terminal, project directory path

BUILD FAILED

D:\androidsdk\tools\ant\build.xml:649:the following error occurred while executing the line:

D:\androidsdk\tools\ant\build.xml:694:return 1

And then execute

Ant Make_channels

Organize the Unity Export Android project using Ant for Multi-channel batch packaging APK

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: info-contact@alibabacloud.com 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.