我已經在示例項目/插件上多次測試過,並且它看起來很完美。一旦我開始整合我的實際項目,就會出現一個錯誤(如下所示)。我已經失去了大約兩週的時間試圖讓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.");
}
您應該向我們展示您的整個堆棧跟蹤。只需在線程的作業(Runnable,AsyncTask等)開頭調用'Looper.prepare()'。 – mstrthealias 2014-08-28 23:43:12