Chainfire/libsuperuser

How to add dependency to Gradle?

Closed this issue · 34 comments

Just a tiny question for this great library please:

How do I add the dependency of this library to Android-Studio? What exactly should I do?

He doesn't want to support Gradle, so unfortunately you have to create a new Library Module in your Android Studio project and manually copy in the required files from libsuperuser.

@afollestad I see. May I ask : How do you usually do those operations?
I'm a newb on Android-Studio (since Google officially ditched Eclipse), so I wonder what is the correct way to import using Gradle and without Gradle.

@AndroidDeveloperLB when you have a project open, File > New Module.

Then you just drag and drop (or Ctrl+C/Cmd+C) files from libsuperuser into the correct folders of your new module. The package name and everything has to match.

@afollestad That's the official way? Isn't there a better way? On Eclipse, I just use the "import..." wizard...
Also, what do you do when you wish to add using Gradle?

@AndroidDeveloperLB for Android Studio, yeah. It has a different project structure than Eclipse. Eclipse ADT is now retired, too, since Android Studio 1.0 was released.

It's not that I don't want to support Gradle, more that I have absolutely no idea what I'm doing. And until I do, I won't be committed anything of the sort. If something Gradle-y needs updating or inclusion, you can open a PR like before.

That's how I was before, too. It's simpler than you'd think. Once you figure out the basics, it's super easy :)

And I will, once I actually start using it, and not a minute before :)

@Chainfire Are you an Eclipse fan like me?
:)

I wouldn't consider myself a fan, no. I've used many IDEs in my life, and I certainly don't consider Eclipse to be the best. That being said, I started using it when I started developing for Android, and now I am comfortable with it. I don't have the time to waste right now to learn how either IntelliJ or Gradle works, and frankly I am annoyed I'm going to need to, for apparently no good reason other than some guys at Google think it's cool.

@Chainfire Well I'm very very used to Eclipse too. Really wished Google would continue working on it, or at least make the alternative as similar as possible to it and as easy as possible to migrate.
For about half of the projects out there on Github that use Gradle, I got weird issues importing and compiling, and even when I tried to migrate my own app I got weird errors that are way harder to understand than any error I've seen on Eclipse.

Gradle is used because you can have a single project without downloading
separate projects and referencing them as libraries. You can reference them
with a version string and they're downloaded for you. If you do use library
projects from folders, you don't have to setup the dependencies every time
you setup a project on a different machine. They're saved in your Gradle file's
dependencies and aren't specific to any machine's paths or anything.

So basically it makes dependency management dramatically easier, especially
with open source libraries and team projects. It's not just because it's
cool.

Gradle integrates with jCenter and any other Maven repositories, too. So again, if takes out the need to download dependencies and add them in as references on your own.

@afollestad Are there any benefits of using it this way, other than having less steps of importing libraries?
According to what I see, I can't see the code or at least not edit the code, and I don't think it has an auto-update (or reminder of updates) for the libraries. Also, I've noticed that it might take less steps, but it's way slower than just downloading libraries and importing them like on Eclipse. So I don't get what are the advantages of using it.

How is it slower? Without it, you have to manually clone every library you're using. In some of my work projects, I have around 10 library dependencies. Before, if I reinstalled an OS on my laptop or used a different machine, I would have to clone 11 repositories and then figure out which ones depend on which.

Gradle does have auto update, too. You use a + sign in place of a version to use the latest.

Whether it's 1.0.0, 1.0.+, 1.+, or +

@afollestad It has auto updates ? Cool ! Does it also mention what's new with each version it gets, and also give you a way to manually cause it to update?
Also, does it allow to tweak the libraries you clone (meaning to change their codes) ?

About being slower, that's what I noticed. It took me much less time to import libraries the normal way (using Eclipse) than to use Android-Studio. Also caused less issues.

It doesn't integrate changelogs, but if a developer wanted to they could include changelogs on the repository a library is hosted on. For an example, I host daterial-dialogs on jCenter (the default Maven repository that Android Studio uses for Gradle dependencies) here: https://bintray.com/drummer-aidan/maven/material-dialogs/view

I could put changelogs on that page for each individual release if I wanted to, I put them on the GitHub repo instead though.

Generally libraries you reference with Gradle are published libraries that a developer would not want you to modify, like the Android Support Library for an example. Android Studio is slower when you're importing code from folders, but when you're copying and pasting 1-line strings to reference libraries it's much faster.

@afollestad Nice. I see I'm writing here too much. May I contact you by email? I can also see you on Hangouts...

@afollestad great that you find those features useful - I certainly don't care as much about them as I care about the time needed to move from one system to another, unlearn the old, and learn the new. Eventually it will be done, as Google has dropped all Eclipse support so it's not like there's a choice, but it's certainly not a priority. Stabs like me not wanting to support it, or countering with how easy it is when I say I won't do it until I understand what I'm doing (which I think is pretty sane, but hey, that's just me), are certainly not progressing the case.

@Chainfire It's odd though.
I was sure that Google said on one of its lectures on Google IO (maybe fireside-chat) that they won't stop supporting ADT, but just focus on Android-Studio.
It's also odd they've decided it, as they tend to offer multiple choices for their users, and Eclipse is also one of the most popular IDEs out there.

@afollestad I have actually started migrating to Android Studio today. A lot of what I'm doing is still Chinese, but I have looked shortly at uploading to jCenter. If you have some pointers, a good how-to, etc, it'd be most welcome as so far I'm not getting anywhere.

@Chainfire nice! Well if you're familiar with Maven, you can put it on Maven Central instead of jCenter. Android Studio allows you to explicitly use Maven Central in addition to jCenter too. But jCenter is easier since it's there by default.

For jCenter, you just create a Maven repository on Bintray (https://bintray.com/), once you deploy your files you can add the repo to jCenter.

I'm not familiar with Maven Central or jCenter. I did create a jCenter account. But I don't know what the steps are. I think (a) turn it into a Maven artifact and (b) publish that to jCenter - but I can't find any docs or examples on how to do this easily. It's seem all the things I can find use intermediate build systems/repos. How hard can this be?

@Chainfire Hey I'm a huge newb in this too. Can you please share your findings?
It might be useful in the future.

Done.

For the dependency ( @afollestad ), see https://github.com/Chainfire/libsuperuser/blob/master/README.md

For the changes to get this working ( @AndroidDeveloperLB ) see
ec7f84c

@Chainfire awesome, thank you!

@Chainfire Seems like a lot. Did you copy it from some existing/general projects?
How long did it take?

I couldn't find a decent guide or example anywhere. So I first rolled my own which was significantly longer and didn't work as well. Then I ran into someone on IRC that gave me his script, and I adapted that.

@Chainfire I see. Thanks anyway.
So, now in order to add the dependency, I need to add this:

compile 'eu.chainfire:libsuperuser:201501111220'

?
It's a bit odd number. I've never seen such a format for dependency (of course, I've seen this format before, but not on Gradle) .
What if I want to add "+" , so that it will auto-update?

The version number just identifies the minute it was built. libsuperuser has no real version number. Saves me the trouble of producing version numbers.

Anyway, I've prefixed it with '1.0.0', so now you can do:

dependencies {
compile 'eu.chainfire:libsuperuser:1.0.0.+'
}

That should work how you want it, no?

Yes, thank you again. You are the best!

I'm sorry, but I cannot find the lib under the maven repo.
Using the instruction in the README.md I get

> Could not find any matches for eu.chainfire:libsuperuser:1.0.0.+ as no versions of eu.chainfire:libsuperuser are available.
  Searched in the following locations:
      https://repo1.maven.org/maven2/eu/chainfire/libsuperuser/maven-metadata.xml
      https://repo1.maven.org/maven2/eu/chainfire/libsuperuser/

Is the maven repo still active?

Using jcenter "fixed" the problem.
Maybe could be useful to add the note in the readme.
It should be sufficient to add jcenter to gradle repositories

repositories {
    mavenCentral()
    jcenter()
}