This article belongs to "unity and iOS, Android platform integration" series of articles , reproduced please indicate the source .
Unity is the default export of the Android-eclipse project, after all, Eclipse for Android development in the last one or two years has only begun to decline, the user volume is very large.
Individuals think that Androidstudio is very useful and can easily solve many of the problems that eclipse cannot solve or is difficult to solve.
So I've divided the andoid project of Unity's export into two parts: Eclipse and Androidstudio.
However, I will use Androidstudio after the relevant content, I hope that still use eclipse students as soon as possible to keep up with ~
This article mainly explains the directory structure of the Android-studio project that unity derives.
Say first in front, this article and "unity" with iOS, Android platform integration: 1, the export of Xcode project very similar, I suggest the hand-tour developers to combine two to see ~
At the same time, I suggest that you complete the integration of sister article "unity" and iOS, Android platform: 2, the export of the Android-eclipse project to establish a complete process awareness system.
The version of the software I use:
Unity 5.3.5F1
Androidstudio 1.3.1
Preamble Step
The first step is to create a new project Unity_build_to_android
The second step, create Plugins/android/libs/jar.jar//In order to demonstrate the native Android Jar package
plugins/android/libs/x86/libnative.so//In order to demonstrate the. So file required by native Android to invoke JNI
plugins/android/libs/armeabi-v7a/libnative.so//In order to demonstrate that native Android calls JNI required. so file
Streamingassets/all_emptytxt.txt//In order to demonstrate the whereabouts of a read-only file with packages in unity
The third step, save the scene, such as
Fourth step, open playersettings, change bundle Identifier (package name), unity inside does not modify not to let export Android ~
Fifth step, choose Android platform, export exported Android project
Sixth step, use Androidstudio to open the Eclipse project
Select Unity to export the Eclipse Project, OK.
Store to the appropriate path, Next.
Three tick all, Finish
Go to the Chase
0, Eclipse-androidstudio
Let's take a look at the structure changes from the eclipse engineering to the Androidstudio project, the import summary generated automatically for the Androidstudio project.
From this file we can see that Androidstudio actually built a new Androidstudio project and then transferred the useful files from the original Eclipse project to the corresponding directory.
The obvious migration is not said, mainly to see the Libs folder in the direction of migration, we can see the *.jar files are transferred to the App/libs folder, */*.so files are transferred to the App/src/main/jnilibs folder */*.so.
1. Program Entrance
Any program has a portal, and Unity's exported Android project is no exception, as we can see, in the Androidmanifest.xml file, the unityplayeractivity is set to the app's portal. (Androidmanifest.xml is one of the Android configuration files, please search by yourself ~)
We can see that unityplayeractivity is inheriting the activity, as to what it is I will not repeat, we can look at this article:activity Detailed (life cycle, Activate activity in various ways, state save, exit completely, etc.)
For the life cycle of an activity, we can see that there is a very useful monitoring of system events, We can also see the corresponding function in Unityplayeractivity.java, which means that we can receive these events in unity, and we will inherit unityplayeractivity and rewrite these listeners.
2, C # C + +
This is a very embarrassing problem, now 5.3.5 version does not support the use of Il2cpp under the Android platform mode, but the 5.4 version is ready to support, which I intend to wait for 5.4 of the version out of the ~
3, Resources Streamingassets, App/src/main/assets
Unity Export Android Project, the original project all kinds of resources are compressed, packaged, encrypted and stored in the App/src/main/assets/bin/data folder, see, this is consistent with iOS, there are many ways to decrypt resources on the Internet, You need to be able to search by yourself.
Let's focus on the Streamingassets folder in unity, about the role of this file, you can take a look at this article:Unity3d Institute of the Hand of the development of all the special folders
As we can see, the all_emptytxt.txt files in the Streamingassets folder are completely copied to the assets folder, which is not just files, but folders are also copied into the folder intact.
As for what this is for, for example, the configuration file is placed here, on the phone debugging can be directly modified in Android project configuration, without the need to re-export Android project in unity.
4, Plugins/android/libs-App/libs, App/src/main/jnilibs
Plugins/android folder usually put some *.jar, *.so files, what these files are, what use, you can look at the official documents:Building Plugins for Android
In the Android-studio project, the *.jar files are transferred to the App/libs folder, and the */*.so files are transferred to the App/src/main/jnilibs folder */*.so.
These files will be copied to the Libs folder and will be compiled at the time of Android compilation.
5, Unity-classes.jar, libmain.so, libmono.so, libunity.so
Unity-classes.jar is a packaged Java class for unity that is used to deal with business in native Android environments, and if interested classmates can go back to compile and see.
The libmain.so, libmono.so, libunity.so files are the underlying CPP written by unity, and of course it contains our C # logic, and since we're not focused on that, we're not going to start talking. (This super-outline, I have not studied ~)
6. Icon
In Unity's player settings is, we can add the corresponding icon
These icon images will be re-compressed, named last placed in the position.
about where to set the icon problem, see the project needs, if the resolution is not enough to go to the export project side to add changes ~
For example: Multi-channel packaging, you may have to replace the icon multiple times, write scripts in the Android project to automate the replacement of packaging is a good choice ~
7. Splash screen
Unity on Android is possible to set up a single picture splash screen, such as.
Android, however, is born without a splash screen, so the app will show a pre-set image in the first activity. To learn more, you can take a look at this article:Android Advanced Guide page series of Splash splash screen logo
Unity's splash screen implementation on Android should also be handled as such, note!! This idea is very important, and the flash screen of unity is the idea.
8, Player Settings, settings
There are a lot of configurations in Unity's player settings that will be reflected in the Android project, in the middle of the circle, these things are not complicated, I will not repeat.
9, Build.gradle
This is not in the previous article, this file can help us to access other SDKs quickly and easily. For gradle files, you can read this article:Android Studio Series Tutorial Four--gradle Basics
"unity" integration with iOS, Android platform: 3, exported Android-studio project