Quantcast
Channel: ARM Mali Graphics
Viewing all articles
Browse latest Browse all 266

Building a Unity Application with Mali Graphics Debugger Support

$
0
0

In the blog Using Mali Graphics Debugger on a Non-rooted device we discussed the idea that you could use Mali Graphics Debugger(MGD) with a non-rooted phone. This blog will take this idea further by showing you how to use MGD with a Unity application on a non-rooted device. Although this can be more complicated than using a standard application, the same principles are used as in the previous guide:

 

  1. Add the interceptor library to your build system.
  2. Edit your activity to load the interceptor library
  3. Install the MGDDaemon application on your device.

 

Let's explore these steps in detail and how to execute them in Unity. For this guide it is assumed that you have an Android application already created in Unity.

 

The first thing you need to do is create an Assets\Plugins\Android folder in your project. Then you need to copy the libMGD.so file into it. The libMGD.so file can be found in the target

\android-non-root\arm\[armaebi-v7a/arm64-v8a] folder in your MGD installation directory. This will make sure that the interceptor library will get packaged into your application.

 

Now the standard activity that is used by Unity when making Android applications won't load the MGD interceptor library by default, so we need to make our own. This is done via eclipse or command line outside of the Unity environment. Here is a template of the code you will need:

 

package test.application;
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.util.Log;

public class StandardActivity extends UnityPlayerActivity
{
    protected void onCreate(Bundle savedInstanceState)    {           try        {            System.loadLibrary("MGD");        }        catch( UnsatisfiedLinkError e)        {            Log.i("[ MGD ]", "libMGD.so not loaded.");        }        super.onCreate(savedInstanceState);    }
}

 

Note that whatever your package is you must make sure that your directory structure matches. So if you have a package of com.mycompany.myapplication, then your StandardActivity.java should be located in the directory structure com\mycompany\myapplication. In the case above you should store the StandardActivity.java in test\application\

 

directory.png

 

As you need some functions that come directly from Android you need to add the Android.jar in your system to the classpath. It is usually located in the platforms\android-<X>\where X is the Android SDK version you are targeting. Also as you are extending from the UnityPlayerActivity class you need to add the Unity classes.jar file, which is located in your Unity folder under the path Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Development\Classes. Finally if

you are using a JDK that is greater than 1.6 you need to add the -source 1.6 and -target 1.6 to your compile line or Unity won't be able to use it correctly.

 

So your full line to compile your java file should resemble something like:

 

C:\scratch>javac -cp "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Development\Classes\classes.jar;C:\android\sdk\platforms\android-21\android.jar" -source 1.6
-target 1.6 test\application\StandardActivity.java

 

or if you are using a Mac

 

javac -cp "/Users/exampleUser/android-sdk-macosx/platforms/android-23/android.jar:/Applications/Unity/PlaybackEngines/AndroidPlayer/Variations/mono/Release/Classes/classes.jar" -source 1.6
-target 1.6 test/application/StandardActivity.java

 

We then need to turn this class into a jar file so we can include it into our Unity project. To do that we need to write:

 

jar cvf myActivity.jar test\application\StandardActivity.class

 

Place the created jar file in your project's Assets\Plugins\Android folder you created in the first step.

 

Now just because we have created a new activity class doesn't mean that Unity is going to use it. For this to happen we also need to override the Android Manifest file that Unity uses. If you create an AndroidManifest.xml file in your assets\Android folder Unity will automatically use this one instead of the default one that is provided. The minimum that is recommended to put in this file is:

 

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android">  <application android:icon="@drawable/app_icon" android:label="@string/app_name">    <activity android:name="StandardActivity"             android:label="@string/app_name">        <intent-filter>            <action android:name="android.intent.action.MAIN" />            <category android:name="android.intent.category.LAUNCHER" />        </intent-filter>    </activity>  </application></manifest>

 

Where activity android:name is the name of the activity you have created. Once this has finished you should be able to build your Android application in the usual way. One final thing to note is that your bundle in Unity must match the package that you gave to your activity. In our example this would be test.application (case sensitive).

redoScreenshot.png

 

Once your application has been built install it onto the device and then install the MGDDaemon app onto your device and use MGD. If you need more information about using and installing the MGD application consult the blog post: Using Mali Graphics Debugger on a Non-rooted device


Viewing all articles
Browse latest Browse all 266

Trending Articles