标签:handler ref 没有 process rar runtime activity load pre
背景:采用Google VR SDK for Unity 开发3D场景功能,然后导出Android项目,合并到一个Android App里面,供其它Activity调用。
1 Intent googleUnityIntent = new Intent(this, GoogleUnityActivity.class); 2 AndroidActivity.this.startActivity(googleUnityIntent); 3 AndroidActivity.this.finish();
如果是自定义的Activity,则将GoogleUnityActivity.class替换成自定义的Activity.class。
1 AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 2 AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); 3 jo.Call("someAndroidMethod");
someAndroidMethod为写在GoogleUnityActivity中的Android方法。
如果该Android方法中需要调用到mUnityPlayer,则需要把调用mUnityPlayer的代码写在Android的UI线程里面,否则会出错:
1 public void someAndroidMethod() { 2 runOnUiThread(new Runnable() { 3 @Override 4 public void run() { 5 mUnityPlayer.quit(); 6 } 7 }); 8 }
AndroidRuntime: FATAL EXCEPTION: main Process: com.elfnaga.googlecardboard, PID: 6401 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.elfnaga.googlecardboard-1/base.apk"],nativeLibraryDirectories=[/data/app/com.elfnaga.googlecardboard-1/lib/arm64, /data/app/com.elfnaga.googlecardboard-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn‘t find "libgvrunity.so" at java.lang.Runtime.loadLibrary(Runtime.java:367) at java.lang.System.loadLibrary(System.java:1076) at com.google.unity.GoogleUnityActivity.<clinit>(GoogleUnityActivity.java:55) at java.lang.Class.newInstance(Native Method) at android.app.Instrumentation.newActivity(Instrumentation.java:1068) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2374) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535) at android.app.ActivityThread.access$1100(ActivityThread.java:154) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1396) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5582) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 12-01 10:20:38.089 13512-14679/? W/ActivityManager: Force finishing activity com.elfnaga.googlecardboard/com.google.unity.GoogleUnityActivity
原因是Google VR SDK for Unity中的libgvrunity.so只提高了armv7版和x86版,没有提供arm64版本,所以需要修改Android项目中的build.gradle,添加产品偏好:
1 android { 2 productFlavors { 3 armv7 { 4 ndk { 5 abiFilter "armeabi-v7a" 6 } 7 } 8 x86 { 9 ndk { 10 abiFilter "x86" 11 } 12 } 13 fat 14 } 15 }
则不会出现找不到libgvrunity.so。
原生Android App项目调用Untiy导出的Android项目
标签:handler ref 没有 process rar runtime activity load pre
原文地址:http://www.cnblogs.com/elfnaga/p/6152948.html