First, we need a computer that's already configured to develop Android apps, and I'm using the Windows System +eclipse+adt development environment, and of course I can use Android Studio or Mac systems.
Export to eclipse Setup U3d project
First you need to set up the game platform for Android:
In Player Settings ... In the panel, remember to set:
This name needs to be set.
Export Android Project
After setting up the Android configuration, we need to export the Android project, we still click on the builder Setting, tick the export project:
We export the project to the specified folder and note that we need to select the path of the Android SDK and JDK during the export process.
Import Project
We open eclipse to import the current project:
It is important to note that if our current workspace and exported folders match the error "Invalid Project description", the solution is that the folders we export are inconsistent with the workspace folders, as follows:
As above, my export path is the Androidoutput folder, and my eclipse's workspace is the Android folder.
Unity and Platform Interaction
On Android side, we are going to modify the Unityplayernativeactivity.java file:
AndroidCallUnitythe method
You can use static methods directly:
Unityplayer.unitysendmessage (String arg0, String arg1, string arg2);
Let's take a look at his 3 parameters:
- First parameter: The name of the Gameobject in the scene.
- Second argument: Call the name of the method that exists on the gameobject.
- The third argument: passed arguments, where only string types are used.
For example: There is a gameobject called "Androidinterface" in our scene, and a script is bound to it, there is a method called "Androidcallback" in the script. Then we can use the following code to invoke the method on the Android platform:
Unityplayer.unitysendmessage ("Androidinterface", "Androidcallback", "" ");
Interestingly, the access rights of methods in unity are not necessarily public, and can be called using protected and private.
UnityCallAndroidthe method
Unity calls the Android method first to get to the Androidjavaobject object, while the method called must be defined in the Unityplayernativeactivity class, let's look at the following script:
1 usingSystem;2 usingUnityengine;3 4 /// <summary>5 ///scripts related to Android platform interaction.6 /// </summary>7 Public classAndroidinterface:monobehaviour8 {9 Private Staticandroidinterface _instance;Ten One Public Staticandroidinterface getinstance () A { - if(_instance = =NULL) - { the Throw NewException ("androidinterface is not initialized!"); - } - return_instance; - } + - PrivateAndroidjavaobject _activity; + A voidAwake () at { - if(_instance! =NULL) - { - Throw NewException ("Gamedebug is singleton!"); - } -_instance = This; in -Androidjavaclass Javaclass =NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer"); to_activity = javaclass.getstatic<androidjavaobject> ("currentactivity"); + } - the /// <summary> * ///popup asks whether to exit the dialog box. $ /// </summary>Panax Notoginseng Public voidShowquitdialog () - { the_activity. Call ("Showquitdialog"); + } A the /// <summary> + ///The dialog box pops up. - /// </summary> $ /// <param name= "title" >title.</param> $ /// <param name= "Content" >content.</param> - Public voidShowDialog (stringTitlestringcontent) - { the_activity. Call ("ShowDialog",New string[]{title, content}]; - }Wuyi}
We call the method of the corresponding name in the Unityplayernativeactivity class with the following call:
Androidinterface.getinstance (). Showquitdialog ();
At the same time, the Java approach can also be protected and private access, while the parameters passed are unrestricted.
Debug program
(Note: My side uses the simulator to run the egl_emulation error, debugging is actually unsuccessful, but after the release is OK to run.) )
Select "Run"-"run".
Publish the installation package
Since it is already an Android project, it is no longer possible to use Unity3d to publish, but it is easier to publish :
Select Project Right click, "Android Tools"-"Export Signal Application Package", we need to use a keystore, not created.
Summary of issues
Import Android Project failed: http://www.crifan.com/adt_android_invalid_project_description_overlaps_the_location_of_another_project/
Android Simulator startup error: http://blog.csdn.net/yu413854285/article/details/7559333
Installation error:install_failed_container_error:http://www.cnblogs.com/lovecode/articles/3658211.html
Unity3d Transplant Study notes: porting to Android platform