[英]Unity C# and Layar SDK Java - AndroidJavaException
I'm Trying to Integrate Layar SDK to Unity. 我正在尝试将Layar SDK集成到Unity。 But I've got some issue.
但是我有一些问题。
Here is the AndroidManifest.xml 这是AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.layar.player"
android:versionCode="1"
android:versionName="8.5.2" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="23" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<application>
<activity
android:name="com.layar.sdk.LayarSDKActivity"
android:launchMode="singleTask"
android:screenOrientation="nosensor"
android:theme="@android:style/Theme.Light.NoTitleBar" />
<activity
android:name="com.layar.player.geo.FilterSettingsActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:theme="@style/FilterTheme" />
<activity
android:name="com.layar.LayerDetailsActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:theme="@style/LayarTitleTheme" />
<activity
android:name="com.layar.WebActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:theme="@style/LayarTitleTheme" />
<activity
android:name="com.layar.ShareSocialActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:theme="@style/Layar.Theme.Default" />
<activity
android:name="com.layar.VideoActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:theme="@style/FullScreenTheme" />
<activity
android:name="com.layar.AudioActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:theme="@style/SmartDialogTheme" />
<activity
android:name="com.layar.ScreenshotActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="nosensor"
android:theme="@android:style/Theme.Light.NoTitleBar" />
<activity
android:name="com.layar.ShareOnFacebookActivity"
android:theme="@android:style/Theme.Light.NoTitleBar"
android:windowSoftInputMode="stateAlwaysVisible|adjustResize" />
<receiver
android:name="com.layar.localytics.CloseSesionBroadcastReciever"
android:exported="false" >
<intent-filter>
<action android:name="com.layar.close_session" />
</intent-filter>
</receiver>
</application>
and This is My c# 这是我的C#
using UnityEngine;
public class IntegrationLayar : MonoBehaviour {
private AndroidJavaObject LayarSDK = null;
private AndroidJavaObject activity = null;
private AndroidJavaObject context = null;
private string oauthKey = "code";
private string oauthSecret = "code2";
void Start ()
{
if (LayarSDK == null)
{
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
context = activity.Call<AndroidJavaObject>("getApplicationContext");
//activity.Call("runOnUiThread", new AndroidJavaRunnable(runOnUiThread));
Debug.Log("unity3D JAVA - Working");
}
using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.layar.player"))
{
if (pluginClass != null)
{
Debug.Log("Layar Java - Working");
pluginClass.CallStatic("initialize", context, oauthKey, oauthSecret);
pluginClass.CallStatic("startLayarActivity", context);
}
}
}
}
}
Error : 错误 :
AndroidJavaException: java.lang.ClassNotFoundException: com.layar.player
AndroidJavaException:java.lang.ClassNotFoundException:com.layar.player
As I understand it, it didn't found a Class named like this in the Java. 据我了解,它在Java中找不到这样的类。 So The problem is what ?
那么问题是什么呢? I'm calling the wrong activity?
我打错电话了吗?
Here is the link to Layar API link 这是指向Layar API的链接
As I see in the Layar API the class is "LayarVisionSDK". 正如我在Layar API中看到的那样,该类是“ LayarVisionSDK”。
AndroidJavaClass pluginClass = new AndroidJavaClass("com.layar.player.LayarVisionSDK")
So Maybe this should work? 所以也许这应该工作?
I certainly doing it wrong but if any of you have a direction to follow, I'll be glad to learn :) 我当然做错了,但是如果你们有任何指导的方向,我将很高兴学习:)
UPDATE 1 : 更新1:
This is from the APK 这是来自APK
Class LayarVisionSDK
java.lang.Object
com.layar.sdk.LayarVisionSDK
So instead of using 所以不要使用
AndroidJavaClass pluginClass = new AndroidJavaClass("com.layar.player.LayarVisionSDK")
I'm using 我正在使用
AndroidJavaObject LayarVisionSDK = new AndroidJavaObject("com.layar.sdk.LayarVisionSDK");
But still not sucessfull. 但是仍然没有成功。 I'm asking myself if the problem may be not where it seem to be.
我在问自己,问题是否可能出在哪里。
UPDATE 2 : 更新2:
OK ! 好 ! I found why I get this error, the API doc was not updated so i checked in the java package and found where was the "initialize" method.
我发现了为什么收到此错误的原因,API文档未更新,所以我检查了Java程序包,发现“ initialize”方法在哪里。
So here is the new c# code. 这是新的C#代码。
using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.layar.sdk.LayarSDK"))
{
if (pluginClass != null)
{
Debug.Log("SDK LAYAR FOUND !!! ");
pluginClass.CallStatic("initialize", context, oauthKey, oauthSecret);
Debug.Log("INITIALIZED");
//pluginClass.Call("startLayarActivity", context);
}
}
But I got a new error : 但是我遇到了一个新的错误:
AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/ContextCompat;
Am I missing a android library? 我是否缺少Android库?
Ok I'm make it work ! 好吧,我让它正常工作!
I just add android support lib and kotlin lib. 我只是添加了android support lib和kotlin lib。
Thanks for your help :) 谢谢你的帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.