Can someone please explain the expectations for Android Library Projects (i.e.: projects with Java code and a build.gradle) in a Unity project in 2019.4? I have read the documentation here:
but it is is extremely unhelpful in this regard, and just redirects you to the Android SDK documentation for making a library project.
Where should they live?
How should they be named?
How do I merge resource folders from a library project into my exported Android project?
How do I merge AndroidManifest.xml data from my library project into my exported Android project.
Create Android Library project using Android Studio
Copy the project folder into Unity project giving folder a name with .androidlib “extension”
Select the folder and make sure the settings in Plugin Inspector are correct
(Optional) You probably want your library project to only contains source files and delete all intermediate files, that generated during build.
The .androidlib folder can be placed anywhere in Unity project, just like any other plugin. Manifest and resources should be merged automatically.
If you have any issues with build, the best approach is to export project from Unity and open it with Android Studio. You should find all your library projects in there with all files, hopefully that will help finding the issue (could be manifest incompatibilities or issues with gradle files).
Please read my post again. Following these steps results in my res folders not being merged into unityLibrary. I am testing under 2019.4.12f1. I directly copied the directory of a test Android library project created in Android Studio. It is named “testlibrary.androidlib”.
I have a drawable resource named image.png that is nowhere to be found in the exported Android Studio project:
My manifest contains a meta-data element that is not present in the exported AndroidManifest.xml for unityLibrary:
I do not understand what you mean when you say:
because the Inspector pane shows nothing when I select the folder:
Ahgrr, dammit, didn’t pay attention that you are on 2019.4!
There is a bug in our documentation (being fixed). The .androidlib stuff applies only to 2020.1 and newer!
You have to place that folder under Assets/Plugins/Android in 2019.4 and older. Folder name doesn’t matter.
Have you moved you library in Unity Editor?
Better use file manager and delete .meta file related to that folder to force Unity to reimport it. When you select the folder, you should see plugin settings.
Once you see proper plugin settings, after build the entire folder should appear in your exported project (better do a clean export to be sure) and gradle scripts should be pointing to it.
Unfortunately, it seems in 2019.4 we only support the library projects that are in the old format.
Here is the example of one:
In short:
you need project.properties file, copy it from the link above
gradle file and android manifest have to be in the root
java sources go straight to src folder, no subdirs
TBH, I don’t know if all rules above are mandatory (the project.properties certainly is), just that this format does import properly.
Unfortunately, I don’t remember, whether Plugin Inspector did show up for these folders in 2019.4, but these folder surely are copied over if correct project.properties file is found in them.
Okay, yes. The project.properties file was the key. Thanks!
However, this pulls the entire library project folder into my exported Android project as a subproject. What I’m wondering at this point is if there’s a way to have Unity merge this project into the unityLibrary project. Kind of like what it’s already doing for loose Java source files in the project already when you mark them to be included in Android builds. Specifically, I would want to:
Merge my library’s AndroidManifest.xml into unityLibrary’s AndroidManifest.xml
Merge my library’s build.gradle (in particular, the dependencies) into unityLibrary’s build.gradle
Merge my library’s res folder into unityLibrary’s /src/main/res folder
For my particular use case, we extend UnityPlayerActivity.java, which is now a loose source file in the project instead of being in the classes.jar as it was in prior versions of Unity. That project needs to merge all of those files into unityLibrary so it has access to the UnityPlayerActivity class.
Android Library projects are meant to work like that - included into project as subprojects.
For your needs it looks like you should be using custom manifest/gradle scripts instead.
Ok, that makes sense. We do have some of these bases covered with our build system, but I just wanted to double check and make sure there wasn’t anything in Unity already that could handle this for me.
Thank you for the help. I would strongly recommend that your documentation team add what we have discussed to the documentation page I linked for 2019.4. Looking back, many of these requirements were present in older versions of the documentation, so it confuses me that they were removed if nothing about the requirements for Android library projects changed in 2019.4