- Home /
Android Unity Plugin problem
I am trying to make a Android plugin for unity but i am getting this error "AndroidJavaException java.lang.ClassNotFoundException: com.example.androidhook"
I have this as my Android code
package com.example.androidhook;
import android.os.Bundle;
import android.util.Log;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
public class UnityBridge extends UnityPlayerActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("TAG","Static method was called");
UnityPlayer.UnitySendMessage("GameObject", "Hello", "READY");
}
}
And here is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.androidhook">
<application android:icon="@drawable/app_icon" android:label="@string/app_name">
<activity android:name=".UnityBridge"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is my C# code
using UnityEngine;
using System.Collections;
public class Done : MonoBehaviour {
public GUIText guiText;
public void Start ()
{
Invoke ("adds", 2.0f);
}
public void adds()
{
AndroidJNI.AttachCurrentThread();
AndroidJavaClass androidClass = new AndroidJavaClass("com.example.androidhook");
}
public void Hello()
{
guiText.text = "hello";
}
}
I have the manifest file and the .jar file in the folder Plugins/Android.
Please could you advise me on what i need to do next thanks
But avoid using onCreate method or any lifecycle callbacks in general, create your own.
What do you mean by thread?
Answer by Yury-Habets · Dec 14, 2014 at 02:40 PM
Try this:
AndroidJavaClass androidClass = new AndroidJavaClass("com.example.androidhook.UnityBridge ");
And you also don't need to call AndroidJNI.AttachCurrentThread() if you are using AndroidClass/AndroidObject API, it is needed for "raw" JNI: http://docs.unity3d.com/ScriptReference/AndroidJNI.html
@Yury Can i use AndroidClass/AndroidObject APIs from another thread? (not the scripting thread) without attaching a V$$anonymous$$ ?
Your answer
Follow this Question
Related Questions
Creating Unity Plugin 1 Answer
Access app_icon from an Android Plugin 2 Answers
Integrate android eclipse project in unity3d 0 Answers
A node in a childnode? 1 Answer
Where to get official support for the Google Play OBB Downloader plugin? 1 Answer