我已经在示例项目/插件上多次测试过,并且它看起来很完美。一旦我开始整合我的实际项目,就会出现一个错误(如下所示)。我已经失去了大约两周的时间试图让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