In Unity 5.6, the follow code works when when application is built to Android:
using (AndroidJavaClass player = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
However, in Unity 2017.1 and 2017.2, this line of code causes a crash. Here is the log from logcat:
FATAL EXCEPTION: main
Process: com.mycompany.ProductName, PID: 19082
java.lang.Error: FATAL EXCEPTION [main]
Unity version : 2017.2.0b9
Device model : samsung SM-G930V
Device fingerprint: Verizon/heroqltevzw/heroqltevzw:7.0/NRD90M/G930VVRS4BQH1:user/release-keys
Caused by: java.lang.NoSuchMethodError: [COLOR=#ff4d4d]No direct method <init>(Landroid/content/ContextWrapper;)V in class Lcom/unity3d/player/UnityPlayer; or its super classes (declaration of 'com.unity3d.player.UnityPlayer' appears in /data/app/com.mycompany.ProductName-1/base.apk[/COLOR])
at com.google.unity.GoogleUnityActivity.onCreate(GoogleUnityActivity.java:120)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
It seems to be a constructor call, but I am not sure as it works properly with Unity 5.6.
In Unity 5.6
public UnityPlayer(ContextWrapper contextwrapper)
But in Unity 2017.1
public UnityPlayer(Context context)
What can we do to successfully build in Unity 2017?
Reference:
Another report of this bug from Google Tango Github:
https://github.com/googlesamples/tango-examples-unity/issues/102