帖子
帖子
用户
博客
课程
显示全部楼层

[BUG] unity3d AR项目生成模块 集成到apicloud中 出现的BUG

[复制链接]
发表于 2018-1-17 17:58:19
看了下官网,目前还有给出可以集成unity3d AR模块的案例 想自己实现一个。
先将unity3d导出成安卓工程包,然后集成到原生中去,这一步已经实现并且可以进行跳转。
现在做的是将原生中的这个生成模块集成到apicloud中去,遇到了很多问题,不过相关问题已经解决一大半,但最后在跳转过程中还是有问题:

跳转报这个 错误 ,并且导致程序崩溃


崩溃后的信息日志如下:

java.lang.Error: FATAL EXCEPTION [main]
Unity version     : 5.6.0f3
Device model      : Xiaomi MI 5s Plus
Device fingerprint: Xiaomi/natrium/natrium:7.0/NRD90M/V9.2.1.0.NBGCNEK:user/release-keys

Caused by: java.lang.RuntimeException: Unable to destroy activity {com.m930820097.erd/com.aaa.aaa.Unity3dActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Handler.sendMessage(android.os.Message)' on a null object reference
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4271)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4289)
    at android.app.ActivityThread.-wrap6(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6321)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Handler.sendMessage(android.os.Message)' on a null object reference
    at android.os.Message.sendToTarget(Message.java:422)
    at com.unity3d.player.UnityPlayer$c.a(Unknown Source)
    at com.unity3d.player.UnityPlayer$c.a(Unknown Source)
    at com.unity3d.player.UnityPlayer.quit(Unknown Source)
    at com.aaa.aaa.UnityPlayerActivity.onDestroy(UnityPlayerActivity.java:44)
    at android.app.Activity.performDestroy(Activity.java:7058)
    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1154)
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4258)
    ... 9 more

好像初始化存在问题。
希望有大神帮忙看下 如果需要什么文件 我可以上传 谢谢。



图片上传失败 重新上传下
T71Z9YCB7}[0K3G4AC19IF4.jpg

UZModule 类脚本

public class UnityModuleTest extends UZModule {
    public UnityModuleTest(UZWebView webView) {
        super(webView);
    }
    ///跳转到unity3d界面(报错)
    public void jsmethod_startActivityUnity(UZModuleContext moduleContext){

        Intent intent = new Intent(getContext(), Unity3dActivity.class);
        //intent.putExtra("appParam", moduleContext.optString("url"));
        startActivity(intent);
    }
    ///跳转到正常界面(没有问题)
    public void jsmethod_startActivity(UZModuleContext moduleContext){

        Intent intent = new Intent(getContext(), MainActivity.class);
        //intent.putExtra("appParam", moduleContext.optString("url"));
        startActivity(intent);
    }
}


这个被跳转的 只是extends UnityPlayerActivity 即可(单独运行时没有问题的可以在手机中实现加载)
public class Unity3dActivity extends UnityPlayerActivity {
    private FrameLayout u3dLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
}
}

//这个脚本是3D渲染在View上的重要脚本 目前就是这个位置出现问题。
package com.aaa.aaa;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;

import com.unity3d.player.UnityPlayer;

public class UnityPlayerActivity extends Activity
{
    protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code

    // Setup activity layout
    @Override protected void onCreate (Bundle savedInstanceState)
    {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);

        getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy

        mUnityPlayer = new UnityPlayer(this);
        setContentView(mUnityPlayer);
        mUnityPlayer.requestFocus();
    }

    @Override protected void onNewIntent(Intent intent)
    {
        // To support deep linking, we need to make sure that the client can get access to
        // the last sent intent. The clients access this through a JNI api that allows them
        // to get the intent set on launch. To update that after launch we have to manually
        // replace the intent with the one caught here.
        setIntent(intent);
    }

    // Quit Unity
    @Override protected void onDestroy ()
    {
        mUnityPlayer.quit();
        super.onDestroy();
    }

    // Pause Unity
    @Override protected void onPause()
    {
        super.onPause();
        mUnityPlayer.pause();
    }

    // Resume Unity
    @Override protected void onResume()
    {
        super.onResume();
        mUnityPlayer.resume();
    }

    // Low Memory Unity
    @Override public void onLowMemory()
    {
        super.onLowMemory();
        mUnityPlayer.lowMemory();
    }

    // Trim Memory Unity
    @Override public void onTrimMemory(int level)
    {
        super.onTrimMemory(level);
        if (level == TRIM_MEMORY_RUNNING_CRITICAL)
        {
            mUnityPlayer.lowMemory();
        }
    }

    // This ensures the layout will be correct.
    @Override public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
        mUnityPlayer.configurationChanged(newConfig);
    }

    // Notify Unity of the focus change.
    @Override public void onWindowFocusChanged(boolean hasFocus)
    {
        super.onWindowFocusChanged(hasFocus);
        mUnityPlayer.windowFocusChanged(hasFocus);
    }

    // For some reason the multiple keyevent type is not supported by the ndk.
    // Force event injection by overriding dispatchKeyEvent().
    @Override public boolean dispatchKeyEvent(KeyEvent event)
    {
        if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
            return mUnityPlayer.injectEvent(event);
        return super.dispatchKeyEvent(event);
    }

    // Pass any events not handled by (unfocused) views straight to UnityPlayer
    @Override public boolean onKeyUp(int keyCode, KeyEvent event)     { return mUnityPlayer.injectEvent(event); }
    @Override public boolean onKeyDown(int keyCode, KeyEvent event)   { return mUnityPlayer.injectEvent(event); }
    @Override public boolean onTouchEvent(MotionEvent event)          { return mUnityPlayer.injectEvent(event); }
    /*API12*/ public boolean onGenericMotionEvent(MotionEvent event)  { return mUnityPlayer.injectEvent(event); }
}
216
帖子
5
勋章
5917
Y币
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Handler.sendMessage(android.os.Message)' on a null object reference
216
帖子
5
勋章
5917
Y币
看下为什么空,做下空判断看看。。
已解决全部问题 关闭问题
您需要登录后才可以回帖 登录

本版积分规则