I’m trying to build a simple AAR plugin which needs to use Unity’s “UnitySendMessage” function to communicate with Unity.
I’ve tried the standard method, not putting the .jar in the libs folder and marking it as provided instead of compile in the gradle build file. That doesn’t work. It includes it in the AAR even when it’s marked as provided. I’ve read that this is just something in Gradle that’s broken.
So I tried the method below, outlined in another thread by “Freezy”.
This doesn’t work either. It still ends up with classes.jar being bundled into the AAR.
Surely there’s some way to do this? Manually removing the file from the AAR every time is ridiculous.
Marking it as “provided” should do the trick. not sure what’s wrong with your project… maybe there’s something else that you did not mention or aware of.
I think it’s more that Unity already includes the contents of classes.jar when it builds anyway so even one plugin including it again means you have two copies and Unity’s build tools cannot resolve that. But possibly I’m wrong and there’s another plugin including it.
I’m not sure about that because most of the tutorials I have been looking at for building plugins have you build the plugin with classes.jar. I’m having a lot of trouble making a plugin because as soon as I include classes.jar and add the plugin to my unity project I can no longer build the unity project. I have facebook and firebase plugins so I don’t know if they’re interfering. Having a lot of trouble learning plugins…
Thanks but I’m afraid this definitely does not work for me.
I removed everything else from the dependencies section of the build.gradle file as you suggested, cleaned and built. I open the resulting AAR file with a zip utility and sure enough classes.jar is still sitting inside the lib folder within the root of the plugin.
Unity’s library is named classes.jar or unity-classes.jar ?
I think that .aar files will always contain the compiled code as a classes.jar file (inside the zip). This is not to be mistaken with Unity’s classes.jar of course
You can peek into the jar as well just to verify: either unzip it, or use a decompiler like jd-gui (that’s what i use).
Yes, but the compiled code from the library is in the root of the AAR. This is in a folder called libs. And yes, I have opened the jar to confirm that it’s the unity classes.
I was having the same issue until I came across the link below. What ended up being the fix was adding the jar as a file dependency under the Project Structure > Dependency window.
Instead of putting Unity’s classes.jar inside the ‘‘libs’’ folder, I put it inside the ‘‘build’’ folder. If you use implementation it will still get the jar to your libs folder in the aar build, however if you replace implementation with ‘‘provided’’ it won’t. Easiest fix I could find.
For me it worket when I put the Unity’s classes.jar into the build folder in Android Studio instead of the libs-folder. Then I right-clicked the library-root (when android is selected) in the small upper left window and clicked open module settings. I added classes.jar as a JAR-dependency to the library project from the build folder root. Also set it as compile only there. Now it no longer copies the unitys classes.jar into the generated aar-files lib-folder (now there was none for me) and unitys build just works onto the device with the plugin. Happy Happy – Joy Joy.