Gradle dependencies on Unity

自闭症网瘾萝莉.ら 提交于 2020-01-13 18:17:45

问题


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://blog.nraboy.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?


回答1:


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.




回答2:


I have, so far, not found a way to make an Android Library Project with external library dependencies using Android Studio. I ended up using Eclipse and it worked like a charm so, if anyone else out there is struggling with this, at least for now, I'd recommend you to use Eclipse instead (this is coming from someone who doesn't really like Eclipse that much).

I won't mark this as a correct answer since it really doesn't answer the original question. So if anyone finds an answer to my original question I'd appreciate it if you could answer, otherwise, I'll leave this one here to help others who might want to create a plugin using external dependencies with Eclipse.




回答3:


I use unity 2017.4.24f1 lts

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

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

edit above template, add android dependencies like regular android project



来源:https://stackoverflow.com/questions/35728875/gradle-dependencies-on-unity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!