googlesamples / unity-jar-resolver

Unity plugin which resolves Android & iOS dependencies and performs version management
Other
1.21k stars 337 forks source link

Using compile(..) instead of implementation(...) in unityLibrary build.gradle #539

Open PickleCubeSoftwareLtd opened 1 year ago

PickleCubeSoftwareLtd commented 1 year ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the question here:

Hello, I am trying to include HBRecorder library. When I build the Android project to work on my implementation, it cannot find the the import statement for the library.

Searching around online, the only way I can get it to import, is if I change the implementation(...) statement to compile(...) inside of the unity libraries' build.gradle. From there I can import, compile and run the application.

Is there anyway I can get this to auto generate the 'compile' statement rather than change it manually every time?

Thanks!

google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

PickleCubeSoftwareLtd commented 1 year ago

I just did some further research, and it seems "compile" is deprecated / not-advised. Instead using api/implementation is the recommended approach.

Considering implementation(...) didn't work for me, I tried api(...) and it works!

api(name: 'com.github.HBiSoft.HBRecorder-2.0.5', ext:'aar')

Rather confused by this 😅

a-maurice commented 1 year ago

Doing some research, it seems that implementation should generally be used instead of api, and the documentation for HBRecorder also says to include it with implementation instead of api.

We'll mark this as a feature request, to add some way to change which it uses, but it seems more likely to be a bug in like the library, or how it is being used, that you need to be using api for it to work correctly.

PickleCubeSoftwareLtd commented 1 year ago

Hi @a-maurice, thanks for the reply.

I actually got it working by using the "Custom main gradle template" in the Player Settings for Android. It turns out the jar-resolver is using the implementation '...' approach, and not pointing to local aar's in the libs folder.

So basically, the same setup as what is suggested in the library project I am trying to use.

This is in a sandbox project for me at the moment, I intend on bringing it in to my main project which uses Firebase, Admob etc. so hopefully it will all place nicely together 🤞

Is there a way to get the jar-resolver to do this from the settings without a custom grade file? i.e. so it doesn't download the aar's and just use the implementation '...' approach?

a-maurice commented 1 year ago

Good to hear that you found a solution. I believe the correct way to handle it is using the custom gradle template, and there currently isn't an alternative beyond that.

PickleCubeSoftwareLtd commented 1 year ago

Yes, this solution works fine for me, I've brought it into my main project!

One question though @a-maurice, it seems to have generated a load of files. Should this be committed to source control or will they get generated at build time? I'm using game-ci/unity and I'm not 100% sure if the jar-resolver will run as a pre-build step during this process?

image