Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle dependencies on Unity

I recently created an Android Studio project using estimote beacons. This requires that the build.gradle be modified so that it can access the estimote sdk. I created the project and it works great. I also created a simple android plugin to show a Toast message from Unity (instructions found here: https://www.thepolyglotdeveloper.com/2014/06/creating-an-android-java-plugin-for-unity3d/).

Now, because we use unity at my job to create apps, now I need to create a plugin for the beacons to be used inside unity, my question is basically, how do I add the gradle dependencies (compile 'com.estimote:sdk:0.9.7@aar') into the library project of Android (a library project, for what I saw, generates no gradle files) and/or into unity so that I can use the beacon code in unity?

like image 737
KeOt777 Avatar asked Sep 13 '25 08:09

KeOt777


2 Answers

I use unity 2017.4.24f1 lts

unity editor > player settings > publishing settings > build > custom gradle template,

it will generate Assets/Plugin/Android/maintemplate.gradle

edit above template, add android dependencies like regular android project

like image 62
chikadance Avatar answered Sep 14 '25 23:09

chikadance


I recommend you take a look at the Unity Jar Resolver project by Google. It does something similar to what adding dependencies in Gradle does. Once you have it integrated, you would then create a class based on SampleDependencies.cs.

  1. Copy SampleDependencies.cs from the jar resolver into an Editor folder
  2. Rename the file and class to be something more useful, eg. "MyDependencies.cs"
  3. Uncomment the body of the class
  4. Add your dependency: svcSupport.DependOn("com.estimote", "sdk", "0.9.7");

By default, the Jar Resolver will run automatically, copying the .aar file into the project. You can turn this off and just do it manually in "Assets > Google Play Services > Settings"

Note: It's called Google Play Services because it's used to import Google Play Services and Firebase .aar files into Unity projects. It should work with other dependencies, but you may need to finagle with some internal code or file system placement if it can't find the source .aar file. From what I can tell, it looks for them in ANDROID_HOME/extras/*/m2respository directories.

like image 35
Ed Marty Avatar answered Sep 14 '25 21:09

Ed Marty