Unity automatic packaging tool and Unity packaging Tool
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. Author: night wind.
How to package unity into android
During compilation, select android in the build and settings options.
How to run the packaged unity file?
First, let's look at your usage experience.