Building Unity Plugin in Eclispe (version 1.4 or later)

In this chapter, we build a jar plugin that will be imported in Unity IDE.

Suppose you have already installed Android Eclipse Plugin in your Eclipse IDE.
There is no need to build and import Unity Plugin in Eclipse anymore from Mobage Unity SDK 1.4.3.
Import the Eclipse project that locates in the Mobage Unity SDK package with the name MobageUnitySDKforAndroid.

Editing AndroidManifest.xml

Edit the AndroidManifest.xml file as follows:

Please rewrite the following terms according to your environment.

  • ${YourActivityFQCN}:
    • Replace with the name of the Activity.
      • Ex)
  • ${YourApplicationId} :
    • Replace with your application’s ID.
      • Ex) 12009999

Importing jar files in Eclipse IDE

Import the three jar libraries: MobageNativeSdk.jar, MobageUnityProxy.jar, and classes.jar in the project that is imported in the previous section. The file hierarchy on the Eclipse project looks like the upper right image.

[import classes.jar]

The file classes.jar is located in Unity IDE application folder. Copy classes.jar from the following path:

  • MAC
    • /Applications/Unity/
  • Windows
    • Unity/Editor/Data/PlaybackEngines/androidplayer/bin/classes.jar

Implementing login handlers

Because Mobage Unity SDK for Android doesn’t provide the C# interface for login handlings, you are required to implement login handlers as Java native codes. Immediately after your application is launched (for example, within onCreate()), invoke the initialization method with the arguments: a region type, an environment type, consumerKey, consumerSecret, an application ID and the root activity. The root activity is required to inherit the class UnityPlayerActivity.

(consumerKey and consumerSecret are issued when you register your application at the developer site. Please set "Consumer Key for SDK" and "Consumer Secret for SDK" values displayed in the "Android application settings" tab on the developer site.)

In addition, there is a need to call Mobage.registerTick() and Mobage.onCreate(this) immediately after the Mobage.initialize in onCreate(). Call the this 2 methods only once in MobageUnitySDKActivity.

After calling Mobage.initialize(), you are required to set a login listener in order to perform the authentication process. For the notifications of the login events to the Unity engine, invoke the methods that belong to the class UnityProxy as follows. 

you should call addPlatformListener() either in onCreate() and onRestart() (below), or only in onStart() (sample code in the SDK).
Since the login listener is removed automatically when onStop is called, need not remove it explicitly.

It is necessary to call the Mobage SDK API in the life cycle method in MobageUnitySDKActivity.

Mobage.registerTick() is used to start a internal Timer and send events to event listeners asynchronously.

In addition, implement the following code to register the Mobage icon resources. 

DON’T use because Unity may replace the identifiers in with other ones.

Generate jar plugin

Please perform the following steps to make a jar plugin for Unity.

[STEP 1] Select “File” --> “Export” on the upper menu.

[STEP 2] Select “Java” --> “JAR file” as the export type.

[STEP 3] JAR File Specification window will open. Select the resources that you want to export, input the JAR file name, and then, push “Finish” button.

Revision History

  • 12/26/2012
    • Initial Release.


Building Unity Plugin in Eclipse (versions older than 1.4)


Building Unity Plugin in Eclispe (version 1.4.5 or later)