Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by markpollard1 · Dec 14, 2014 at 12:18 PM · androidplugin

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Dec 14, 2014 at 08:57 PM 0
Share

But avoid using onCreate method or any lifecycle callbacks in general, create your own.

What do you mean by thread?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image markpollard1 · Dec 14, 2014 at 03:16 PM 0
Share

Yes that worked for me Thanks

avatar image liortal · Dec 14, 2014 at 08:40 PM 0
Share

@Yury Can i use AndroidClass/AndroidObject APIs from another thread? (not the scripting thread) without attaching a V$$anonymous$$ ?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges