Andorid plugins question

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

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 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.

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.

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

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.

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.

Can you confirm that there is this line at the top of your PluginTest.java code (Bundle Identifier is not important in this case):

package com.test.app;

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(“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?

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): Invalid Classname : An exception was thrown by the type initializer for GooglePlayGames.Editor.GPGSDependencies ¡ Issue #1299 ¡ playgameservices/play-games-plugin-for-unity ¡ GitHub

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.

1 Like