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 dfelipe · Feb 25, 2015 at 07:04 PM · c#androidjavajar

I need add .jar project Unity

I use an library .jar in my project.

How add .jar in project Unity and use with C# language?

Thank you

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by tebandesade · Feb 25, 2015 at 10:02 PM

UNITY 1. Create a new Unity project. Switch to the Android platform. 2. Save the empty scene, add it to the build settings. Set the bundle identifier in the player settings. 3. Build and Run the application. You should see the Unity logo and a blue background.

ECLIPSE 1. Open Eclipse with the ADT plugin. If you don't have Eclipse, you can install it from here: http://developer.android.com/sdk/installing/bundle.html 2. Create a new Android Application Project. Name it "[NAME]" 3. Once the project is created, run it on the device to verify it works. 4. Open the Project properties in Eclipse and in the Android tab, tick the "Is Library" option. 5. Create a new class for your Project, named [NAMEPROJECT].

Eclipse will build a .Jar file. You need to copy that file into Unity. The file is found in your workspace. The easiest way to get the path is to select the file in Eclipse and open the Properties window. You can look at what's inside the .jar file if you add the .zip extension to it and open it with any application which can view zip files.

UNITY In the Project view, create a "Plugins" folder. Then create an "Android" folder inside the plugins folder. Create a new C# file in Unity, and name it "CallJavaFromUnity .cs". Then just start calling EXAMPLE

  //The comments describe what you would need to do if you were using raw JNI
      AndroidJavaObject jo = new AndroidJavaObject("java.lang.String", "some_string"); 
      // jni.FindClass("java.lang.String"); 
      // jni.GetMethodID(classID, "<init>", "(Ljava/lang/String;)V"); 
      // jni.NewStringUTF("some_string"); 
      // jni.NewObject(classID, methodID, javaString); 
      int hash = jo.Call<int>("hashCode"); 
      // jni.GetMethodID(classID, "hashCode", "()I"); 
      // jni.CallIntMethod(objectID, methodID);

or

 AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
  // jni.FindClass("com.unity3d.player.UnityPlayer"); 
  AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); 
  // jni.GetStaticFieldID(classID, "Ljava/lang/Object;"); 
  // jni.GetStaticObjectField(classID, fieldID); 
  // jni.FindClass("java.lang.Object"); 
 
  Debug.Log(jo.Call<AndroidJavaObject>("getCacheDir").Call<string>("getCanonicalPath")); 
  // jni.GetMethodID(classID, "getCacheDir", "()Ljava/io/File;"); // or any baseclass thereof! 
  // jni.CallObjectMethod(objectID, methodID); 
  // jni.FindClass("java.io.File"); 
  // jni.GetMethodID(classID, "getCanonicalPath", "()Ljava/lang/String;"); 
  // jni.CallObjectMethod(objectID, methodID); 
  // jni.GetStringUTFChars(javaString);



All these examples are from the documentation

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 fafase · Feb 26, 2015 at 08:09 AM 0
Share

If he did not understand the doc, how is that helping?

avatar image dfelipe · Feb 27, 2015 at 01:38 PM 0
Share

I use your sample, but log show "ClassNotFound" =(

AndroidJavaClass jc = new AndroidJavaClass("com.my.class");

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I use Java callbacks? 1 Answer

Got stuck trying to extend UnityPlayerActivity following example in Unity documentation. 1 Answer

Calling static jar function from Unity3D 0 Answers

Android manifest does not merge with generated manifest. 0 Answers

Read NFC tag from Unity3d android 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