Unity automatic packaging Tool

Source: Internet
Author: User
Tags svn update

At first, I came up with the idea of writing packaging tools because I saw a picture shared by Wang Weifeng of the Three Kingdoms. They had a dedicated "tool programmer" to develop various tools. (PS: Speaking of Wang Weifeng and his founding team members, I used to be in the same company as me. The company name will not be disclosed, but I only knew each other in different departments ). It's just now that our project is coming to a later stage, so we have to prepare access channels. So I wrote our packaging tool by hand. In the following article, the platform refers to the operating system platform, such as IOS, Android, WP8, and Metro. The channel refers to the publishing channel, such as App Store, WP8 store, 91, and Xiaomi.


Packaging tools for the Three Kingdoms shared by Wang Weifeng, CEO of Shanghai huoyan Network


Process

The process can be divided into the following steps:

1. Resource preparation;

2. A project is generated by unity;

3. Generate the installation package;

4. Resource Recovery.

There are some minor differences between platforms and channels.


WP8 Packaging

This is the first write, because it does not involve channels and is relatively simple. From four o'clock P.M. To, I wrote more at, and most of the time was spent on processing some details.


Step 1: Prepare resources. We have made dynamic updates, so before generating the project, we need to delete the updated resources from the unity, so that the output package is smaller. PS: before this step, we will first update the package. I will write another article about resource packaging and update. In addition, for interaction with various platforms, we have written plug-ins. For example, if embedded web functions are not available in unity, we need to call system APIs. This is another common plug-in that took me a lot of time to process, because unity often loads plug-ins under other platform directories. For example, I have a plug-in platform. DLL. According to the official unity documents, put it in the "plugins/platform/" directory. When generating the WP8 project, unity should select plugins/WP8/platform. DLL loading. When playing the android package, you should load plugins/Android/platform. DLL. Unfortunately, this is not the case with unity. When I hit WP8, it often loads the plug-in under the android directory. I have not found the cause of this problem, and I hope you will not give me any advice. To solve this problem, I deleted the plug-ins in the non-current platform directory during packaging, packed the package, and then restored. In addition, you must delete the file generated in the previous package.


Step 2: generate the project. There is nothing to say, that is, unity API calls, such as buildpipeline. buildplayer (buildscenes, buildpath, buildtarget. wp8player, buildoptions. None );


Step 3: generate the installation package. Before generating the package, replace some unity-generated files, such as mainpage. XAML /. CS, because we have implemented the WP8 ApplicationBar for Embedded Web operations; we have configured wmappmanifest. XML, umeng statistics requires that the initialization must be in the app. XAML. in CS, the icon in the assets/directory of the WP8 project. Then, modify the project file as needed. For example, if we have implemented the WP8 ApplicationBar, we need to add related resource indexes to the project file in the packaging tool. Then, you can call cmd to generate the APK installation package. The main idea is to use the vscommand to generate an APK, and use the devenv.exeunder the vsinstallation directory to configure the parameter of includevenv.exe. Note that the build option should be set to master instead of release. The release version has "profiler support", and the master is used for release.


Step 4: Restore the resource. The package has been packaged, and resources are restored for other platforms or channels. For example, restore the updated resources and plug-ins of various platforms.


Android Packaging

Android packaging is troublesome, not because there are many channels, but because some channels have some special requirements. The process is similar. The following describes the differences.


Step 1: Prepare resources. Unlike WP8 packaging, Android is a multi-channel service that processes resources from various channels. I initially put all the channel SDK-related resources and code under the plugins/directory of unity, such as plugins/android, plugins/android91, plugins/androidxiaomi, and so on, in the resource preparation phase, delete all content not related to the current channel, change the Directory Name of the current channel to plugins/Android, pack the package, and then delete plugins/android, call SVN update to update all deleted content. After writing the package, open a pack and click OK. At that time, I took 11 channels and then clicked "build all". The build process was very slow. because there were a lot of prose articles, it would take several minutes for SVN update, it takes some time for unity import to come in with these resources. In addition, when you call the fourth and fifth packages, an error is often reported during unity resource import, probably because the synchronization between files on the disk and the cache files of unity is abnormal. Packaging is too slow, and dozens of packages cannot be packaged with one click. Later, I wanted to put all the channel files out of the Unity Assets Directory. In this way, I needed to copy the files to the SDK and delete the packages without using SVN update, unity does not need to import a large number of prose pieces each time. Packaging efficiency has been improved several times. In addition, a dozen packages can be output with one click, and no unity error has been reported.


Step 2: generate the project. I had some detours in this place.

At the beginning, I did not generate an android project, but directly built the APK. The advantage is that it is fast. According to the test, one can be generated in three minutes, and the time for building the APK after the project is generated doubles. However, the special characteristics of sdks in various channels cause this method to become a problem several times later.


For the first time, the SDK contact said that some channels require independent icons or splash. I think this is simple. Use aapt to directly generate an APK and modify the content, then you can re-sign it, which is fast and convenient.


For the second time, Baidu duoku said that the APK generated using the packaging tool will be crash if UnionPay payment is selected during top-up payment. Build the project first, and then use eclipse to compile the APK generated by the project. I carefully compared the two APK files and found that, in the directly generated APK, there are several fewer files in the Res/drawable/directory than in the APK generated by the project, Data. bin/data_high.bin/data_low.bin/mobilepayplugin. bin. I suspect that the files are filtered out when unity directly generates the APK, but not when generating the project. Why? Solve this problem. Find the missing file and add it with aapt. Later, dangle and OPPO both needed to add the same binfiles to the packaging tool.


This solution is not a good solution, but solves the problem. However, Oppo later reported that the oppo login interface opened by our pack is full screen, but the pop-up window style is actually used. This indicates that some interface layout files may not be included during packaging. However, this time, I cannot compare the APK generated in two ways to find which file is missing, because all resource files are routed to resources. ARSC. At this time, I think this kind of problem solving is wrong, and we should fundamentally reject the problem. Then, I re-wrote the android packaging tool. I made it a project and then used ant to build the APK. If any channel has special requirements, operate the project before creating the APK, such as replacing the icon and splash. Of course, the packaging process becomes half slower.


Step 3: generate the installation package. There is nothing to say about it, such as ant, sign, and zipalign. In addition, our operation has a special requirement. There are two ways for them to serve: Channel SDK and SDK. For the second method, I pack only one package, and then copy the generated package and modify the configuration file in the package to calculate the distribution channels, you do not need to generate multiple packages. In this way, a package can be generated in a dozen seconds. The "spp channel package" button in my packaging tool generates this channel package separately.


Step 4: Restore the resource. WP8 is a channel, so after the WP8 package is completed, all resources must be restored directly. There are many Android channels. For the sake of speed, some resources do not need to be restored, such as the content we update. You only need to complete all android packages and restore them once.


IOS Packaging

After package WP8 and Android, I did not want to repeat the work again. I wrote a detailed document and handed it to a small partner so that he could refer to the WP8 and Android code, writing IOS packaging tools also allows him to exercise and learn. As a result, the tragedy is incomparable !!! Because the code is very similar, and I told him how to do it in detail, IOS only has three channels, and he needs to write no more than 50 lines of code, the shell script is estimated to be less than 30 lines. I had estimated that it would take one to two days for me to finish my work in three days. It would take him a week. Finally, after three weeks, he was unable to output the package with one click. Where are excellent engineers? Trust me. PS: we are a very open team. We need to recruit an iOS developer without experience. As opposed to experience, I pay more attention to basic and learning skills.


Others

When I first wrote the tool, the packaging operation portal used [menuitem (...)], the operation button is on the menu bar on the left of unity. The packaging tool operation interface is as follows:



I don't know if you have any problems. The problem is: Every time I add a channel, I need to add a menu item in the Code. For example, add 91 channels today and add them in the Code:

[Menuitem ("build/build Android player/91")]
Static void buildandroid91player (){

// Do something...

}

The channel will be added tomorrow:

[Menuitem ("build/create Android player/")]


Static void buildandroidplayer (){

// Do something...

}


What if there are dozens or even 100 or 200 channels? Every time I modify the code? No! PS: Our company has a product that has been connected to more than one hundred channels.

However, in addition to functions, how do I read the configuration and assign values to the [menuitem (...)] attribute of C? I was lucky enough to find some information, which is impossible at all. Later, I remembered the figure that Wang Weifeng shared before:



Although this figure is vague, I will take a closer look and see that their packaging tool operation portal is not in the menu bar at the top of unity, but in inspector. After learning about where to write, the implementation is simple. You can create a prefab. In this way, new channels will be added in the future. You only need to add a channel to the configuration file in the format specified by me. After modification, the packaging tool operation interface is as follows:


Our packaging tool operation Portal


The refresh button is used to modify the channel configuration file and then re-read the configuration file.

The buttons Under build Patch are the update packages for each platform.

In build player, installation packages for various platforms and channels are created on a pay-as-you-go basis. You can export a package with one click or all packages on a platform with one click. There is no one-click package for all platforms, because we do not have this requirement. If you want to do this, after you have finished the package of a platform, you can switch to the platform. The interface is editoruserbuildsettings. switchactivebuildtarget (buildtarget. XXX ). However, do not immediately package the new platform after the switch, but do it in the callback interface, activebuildtargetchanged.


Unity-related articles: Unity optimization Summary

For more information, see http://blog.csdn.net/ynnmnm/article/details/36774715. Night breeze.


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.