I am trying to create a google maps view that will display as a subview (or fragment) of my Unity app. What I’ve read so far implies this is possible but I’ve run into many issues.
My problem right now is that if I use
import android.support.v7.app.AppCompatActivity
In my plugin, Unity is no longer able to find the class
I/Unity (29774): AndroidJavaException: java.lang.ClassNotFoundException: com.myapp.mapspluginlib.UnityMapsPluginActivity
I/Unity (29774): java.lang.ClassNotFoundException: com.myapp.mapspluginlib.UnityMapsPluginActivity
I/Unity (29774): at java.lang.Class.classForName(Native Method)
I/Unity (29774): at java.lang.Class.forName(Class.java:309)
I/Unity (29774): at java.lang.Class.forName(Class.java:273)
I/Unity (29774): at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
I/Unity (29774): at com.unity3d.player.UnityPlayer.a(Unknown Source)
I/Unity (29774): at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
I/Unity (29774): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.mapspluginlib.UnityMapsPluginActivity" on path: DexPathList[[zip file "/data/app/com.myapp.MyProject-2/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.MyProject-2/lib/arm, /vendor/lib, /system/lib]]
I/Unity (29774): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
I/Unity (29774): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
I/Unity (29774): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
I/Unity (29774): ... 6 more
I/Unity (29774): Suppressed: java.lang.NoClassDefFoundEr
The class was able to be found when I was using
public class UnityMapsPluginActivity extends Fragment implements OnMapReadyCallback {
instead of
public class UnityMapsPluginActivity extends AppCompatActivity implements OnMapReadyCallback {
But based on their sample code, and the errors I ran into, I believe Google Maps requires I use the AppCompatActivity class.
Here is the function I am trying to call
public class UnityMapsPluginActivity extends AppCompatActivity implements OnMapReadyCallback {
private static Activity activity;
static public void _OpenMapActivity(Activity activity) {
UnityMapsPluginActivity.activity = activity;
Intent myIntent = new Intent(activity, UnityMapsPluginActivity.class);
activity.startActivity(myIntent);
}
...
and here’s how I am calling it
public static void _testPresentSubview() {
AndroidJavaClass androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
// Accessing the class to call a static method on it
AndroidJavaClass jc = new AndroidJavaClass("com.myapp.mapspluginlib.UnityMapsPluginActivity");
// Calling a Call method to which the current activity is passed
jc.CallStatic("_OpenMapActivity", currentActivity);
}
From what I can tell this error is coming from the fact that Unity and support v7 are using different namespaces (or DEXs) so they can’t locate each other. Does anyone know of a way to call a support v7 class from Unity? Or any workaround that would allow me to call a static function from Unity on a class that extends AppCompatActivity?