2014-08-28 24 views
1

我已經在示例項目/插件上多次測試過,並且它看起來很完美。一旦我開始整合我的實際項目,就會出現一個錯誤(如下所示)。我已經失去了大約兩週的時間試圖讓Unity/Android插件工作,而這是我獲得的最遠距離。我感覺如此接近,但從尋找解決方案到目前爲止!任何幫助,我可以得到非常感謝。謝謝!Unity到Android插件錯誤:無法在未調用Looper.prepare()的線程內創建處理程序

是我得到的錯誤:

08-28 15:38:25.200:I /統一(6191):AndroidJavaException:了java.lang.RuntimeException:無法內螺紋創建的處理程序有沒有所謂Looper.prepare()

C#(統一):

// Update is called once per frame 
void Update() { 
    testPlugin(); 
    printTestobj(); 
} 

public void testPlugin() { 

    if (testobj == null) { 
     // First, obtain the current activity context 
     using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { 
      playerActivityContext = actClass.GetStatic<AndroidJavaObject> ("currentActivity"); 
     } 

     // Pass the context to a newly instantiated TestUnityProxy object 
     using (var pluginClass = new AndroidJavaClass("com.company.product.Main")) { 
      if (pluginClass != null) { 
       testobj = pluginClass.CallStatic<AndroidJavaObject> ("instance"); 
       testobj.Call ("setContext", playerActivityContext); 
      } 
     } 
    } 
} 

的Java(Android版):

public Main() { 
    INSTANCE = this; 
} 

public static Main instance() { 
    Log.i(TAG, "Inside instance."); 
    if (INSTANCE == null) { 
     Log.i(TAG, "instance b1."); 
     INSTANCE = new Main(); 
     Log.i(TAG, "instance b2."); 
    } 
    Log.i(TAG, "instance b3."); 
    return INSTANCE; 
} 

public void setContext(Context ctx) { 
    this.context = ctx; 
    Log.i(TAG, "Application context set."); 
} 
+0

您應該向我們展示您的整個堆棧跟蹤。只需在線程的作業(Runnable,AsyncTask等)開頭調用'Looper.prepare()'。 – mstrthealias 2014-08-28 23:43:12

回答

-1

我不知道這是否已被回答,但我添加了此評論以幫助保持此問題的活力。

第一步是找出存在問題的代碼行。你不知道,因爲Unity不會告訴你。

我也在爲Unity開發Android插件。我看到的一個問題是RuntimeException被Unity層捕獲,而自然棧跟蹤似乎被Unity想要插入的東西所取代。

直到單元開始顯示棧軌跡而不是捕捉它們並顯示不同的東西,這些類型的東西將不可能解決。畢竟,如果你必須猜測發生錯誤的代碼行,你怎麼能解決一個錯誤?

相關問題