0

I'm Trying to Integrate Layar SDK to Unity. But I've got some issue.

Here is the 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#

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

As I understand it, it didn't found a Class named like this in the Java. So The problem is what ? I'm calling the wrong activity?

Here is the link to Layar API link

As I see in the Layar API the class is "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 :

This is from the 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 :

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.

So here is the new c# code.

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?

0

2 Answers 2

1

Make sure you have android-support-v4.jar under a Plugins/Android/libs folder.

You can download the file from here.

Sign up to request clarification or add additional context in comments.

1 Comment

That's what I did this night, But now I got a new Error - AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: LKotlin.Pair
0

Ok I'm make it work !

I just add android support lib and kotlin lib.

Thanks for your help :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.