Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Andorid plugins question

Discussion in 'Android' started by johnboyman12, Apr 23, 2017.

  1. johnboyman12

    johnboyman12

    Joined:
    Apr 13, 2017
    Posts:
    41
    Hello. In the past with older versions of Unity I could make android plugins with the tutorials that I found on the internet. Now with the newer versions of unity If use the exact same tutorials and build it correctly they just wont load. When I use AndroidJavaClass I always get a null exception even if I load the plugin on my phone.
    So has anything changed for making plugins for android with newer versions of unity and are there any tutorials that can show me how to make a plugin for unity versions past 5.0? thanks bye
     
  2. johnboyman12

    johnboyman12

    Joined:
    Apr 13, 2017
    Posts:
    41
    Heres an article about plugins on unity 5
    https://docs.unity3d.com/Manual/UpgradeGuide5-Plugins.html

    It says this " Plugins are no longer required to be placed in Assets\Plugins<Platform> folders,"

    Then it doesn't tell me where to put them or how to make them. That means huge changed have been made and theres no explanation, thats wierd. Please help.
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    You can put plugins anywhere you want. You then have to click on them and setup platform compatibility settings in inspector.
    If you put plugins in certain directories like in pre-Unity5 before starting Unity editor, then the default settings will be applied matching older behavior.
     
  4. johnboyman12

    johnboyman12

    Joined:
    Apr 13, 2017
    Posts:
    41
    Ok well, its very nice someone answered. Where should I put plugins because it seems like what you said is I can put them anywhere but if I put them in the Assets/Plugins/Android folder it wont work right? Should I put my jar file in assets? Is there anything else. I also heard that versions past 5.0 use .aar files instead of jars is this true or false. Is there any other changes? Thanks alot
     
  5. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    I use Unity 5.6, and I put my jar plugins in Assets/Plugins/Android (it works flawlessly for me). You should perhaps share a fraction of your code that gives error.
     
  6. johnboyman12

    johnboyman12

    Joined:
    Apr 13, 2017
    Posts:
    41
    This is the most simple and straight forward tutorials for making android plugins to me.
    http://www.lorenzonuvoletta.com/how-to-create-a-native-android-plugin-for-unity/
    I have followed the instructions over and over again with all the tutorials I can find , the same thing happens to me every time that I try to run the final built game .apk on my phone or bluestacks. The following line of code will make my app crash unless I catch it and output the exception. the exception is java.lang.ClassNotFoundException


    This is my C# MonoBehaviour that is attached to my camera.

    AndroidJavaClass pluginTutorialActivityJavaClass;

    void Start ()
    {
    AndroidJNI.AttachCurrentThread();
    pluginTutorialActivityJavaClass = new AndroidJavaClass("com.test.app.PluginTest");
    }

    Even if I have my jar file or my .aar file in the Assets/Plugins/Android, my player settings->bundle identifier is set to the correct package name. My manifest sdkmin and target versions are correct.......

    I have tried like ten tutorials everytime I get the same error. I have even made plugins in the past. Its very frustrating. No clue what to do next. Just stuck in a broken record!

    Thanks for any help bye.
     
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Can you confirm that there is this line at the top of your PluginTest.java code (Bundle Identifier is not important in this case):

    Code (CSharp):
    1. package com.test.app;
     
  8. UnSkiLd

    UnSkiLd

    Joined:
    Mar 4, 2015
    Posts:
    20
    Yasirkula, you mentioned that you were able to have it work in 5.6. Did you have to do anything different for it to work? Earlier today I was using my plugin in 5.5.3f1 without any issues. I backed it up and migrated my project to 5.6 and now I can not instantiate my android class:

    using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    {
    unityActivityObject = jc.GetStatic<AndroidJavaObject>("currentActivity");
    }

    with previous version I have no issues and I made no changes to either projects. Now I am getting an 'Operation not permitted' exception:

    04-25 18:57:06.697 21608-21637/com.phatboi.studio W/libc: pthread_create sched_setscheduler call failed: Operation not permitted
    04-25 18:57:13.312 21608-21637/com.phatboi.studio I/Unity: Exception: An exception was thrown by the type initializer for com.phatboi.Studio.PhatPlugin


    I do notice that the last line have parts of the namespace camel cased..not sure why it did that.

    Any thoughts?
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    I haven't done anything special for 5.6. I have used Jinbom Heo's method there to create my plugin and put it in Assets/Plugins/Android.

    It doesn't look like the code you have shared is causing any problems as the error message says it is about "com.phatboi.Studio.PhatPlugin". Also, I believe you can ignore the "pthread_create sched_setscheduler call failed" warning, it is likely unrelated with the issue you are having.

    This link suggests that your issue might be related to some missing/outdated Android SDK components (if not, then it can also be related with the camel case issue you have mentioned): https://github.com/playgameservices/play-games-plugin-for-unity/issues/1299
     
  10. UnSkiLd

    UnSkiLd

    Joined:
    Mar 4, 2015
    Posts:
    20
    Thank you Yasirkula for the information and I apologize for not giving you a lot to go on. I'll check those links and keep digging.
     
    yasirkula likes this.