Building APK file in Unity

This page is based on latest Mobage Unity SDK 1.4.7 . For older version please see the archives .

The goal of this chapter is to build an apk file in Unity IDE.

  • Import Mobage Unity SDK assets and jar plugin generated in the previous chapter.
  • Implement your Unity program.
    you are expected to have completed the download, installation and license registration of Unity.
     

    Import Mobage Unity SDK assets in Unity IDE

    First, launch Unity and create a new Unity Project. While opening the newly created
    project, choose "Assets">"Import Package">"Custom Package..."

In the dialog that appears, specify a path to MobageUnitySDK.unitypackage.
Check all the options, and press the "Import" button at the right bottom to complete the import.

Notice that If the path to MobageUnitySDK,unitypackage has a multibyte character on Windows systems you will fail to import.

Open HelloMobage.unity

After importing the package, you can see the imported files in Project View.
Open a template asset to double click Plugins/HelloMobage.unity (Unity icon file) in the Project view. Then you can see the MobageCallback object in Hierarchy View.
(The following image shows the outline of the Project View with Wide layout.)

Check the preview screen

The sample settings to show a button are now complete. When you press the replay icon at the top of the Unity IDE, the game preview screen is shown as below.

Editing scripts in Unity IDE

To perform login process, you are required to set a login listener that receives events from Mobage Unity SDK.

Set a login listener

To use Mobage Unity SDK functions, please setup Plugins/Mobage/samples/Config.cs.

 

Calling MobageCallback.AddCallback()

You will need to add AddCallback() method in the beginning of Awake() method from Mobage Unity SDK 1.4.7 .

Below is Awake() method example.

Calling MobagePlatform#initialization()

Call the initialize method on application start up like inside Awake() method.

Set the region, serverMode, consumerKey, consumerSecret, appId Arguments for MBGPlatform#Initialize.

The consumerKey, consumerSecret, appId are provided when you register the application on Mobage Developers. Set the "Consumer Secret for SDK" and "Consumer Key for SDK" from "Android Application Settings" on Mobage Developers.

Add Login Listener

To recieve Login status events you will need to add listener as below.

 Sample API call: get the user information by C# script

The following is a sample code to call MobagePeople.getCurrentUser().

API Reference

Example

Modifying AndroidManifest.xml on UnityIDE

Edit Plugins/Android/AndroidManifest.xml from Project view.
The folder tree is as below.

AndroidManifest.xml

AndroidManifest.xml will be as below.

Setting the MobageDashboardActivity's screenOrientation to landscape will show the Mobage UI in landscape.
Until May 28 2014, we requested to set launchMode to either singleTop or standard. For now on when using Unity SDK, please set the launchMode to singleTask.

Please replace the following ID depending to your environment.

  • ${YourApplicationId}
    • Replace the to your App ID.
      • Ex) 12009999

Unable to render {include} The included page could not be found.

Building an apk file

When selecting "File"->"Build Settings" in the Unity IDE (the lower left image), the Build Settings Window will open (the below image).

Selecting platform

Select “Android” in “Platform” that is at the bottom-left of the Build Settings Window (the below image). Push ”Switch Platform” to configure Android platform settings.

Configure UnityPlayer

When pushing ”Player Settings...”, UnityPlayer configuration pane will be shown in Unity IDE. Configure the following required settings.

Bundle Identifier configuration

When pressing the "Play Settings..." button, the setting items are shown in the Inspector view in the IDE window. Change "Other Settings" ->"Identification"->"Bundle Identifier" from the default value.

If you do not change the Bundle identifier, you will not be able to build.
Please keep "Player Settings" -> "Stripping Level" as "Disabled" which is default settings. If you are planning to use other than the default setting please add the following on the link.xml under Assets

 

Perform apk build process

When pressing the "Build" button at the bottom-right of the screen, a building process will start.
A dialog to set a path to Android SDK will be shown.
And then, a dialog to specify an apk file name will be shown (the below image).
Specify the apk file name and push the “Save” button. The apk file will be saved.

This apk file is the final output of the building process.
If you want to check the performance of the application, push “Build and Run” button at the bottom-right of “Build Settings” window.


Revision History

  • 09/11/2014
    • Updated documentation for Mobage Unity SDK 1.4.7
  • 07/11/2014
    • Added How to Import Google Play service SDK.
  • 06/02/2014
    • Added AndroidManifest. The launchMode has been set to singleTask as default.
  • 08/08/2012
    • Initial Release.

PREVIOUS

Contents

NEXT

Mobage Unity SDK for Android (Archives)