1

I'm new to Android Studio, and I want to include an OAuth2 client implementation to use in my application.

The client is just posted as a collection of source files. Ideally, I'd like to be able to include the classes automatically using gradle, but it doesn't seem like that's possible if it's not at least supporting Maven. I'd like to at least include the code in my project as a git submodule, so I can rely on git to integrate any future changes in the client library.

From what I can gather, I think the right way to include a library in a project would be as a module. It doesn't seem like there's any way to create a new module with existing source. The only thing I can figure out to do is create a new module and move the source files into that module, but that seems really messy. Is that really my only option to include this kind of code?

sak
  • 2,612
  • 24
  • 55

3 Answers3

2

Go to

File > Project Structure

Click the green + button on top left.

Import existing project > tell where module is located > hit next

Till now you have added the module to your project.

Now put that module as a dependency in your app module (or mobile module)

Way 1 :

again go to

File > Project Structure

Click on app (or mobile) in modules sectino.

Now dependencies tab and there will be a green + button on top right. Click that.

Chose module dependency from dropdown options. The module you imported will be listed there. Select it and hit ok. and ok again on previous window.

If no errors gradel will compile and you are all good to go and use the library!

Way 2 :

Also, after importing the lib in project you can add the lib as a dependency to your app module by changing its build.gradel file and adding

dependencies {
    compile project(':nameoflib') //nameoflib is the name of lib you imported
}

In case you are having errors importing lib to project. feel free to ask me in coments.

Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41
  • What do you do when you click "File" and "Project Structure" is visible but greyed out? – Dronz Mar 30 '19 at 23:37
1

You can either add the library code as module or as part of the app module (if you will modify some part of the library).

The only thing I can figure out to do is create a new module and move the source files into that module.

Yes, that is the only option for now in Android studio.

suresh
  • 266
  • 1
  • 7
0

First time I've seen that trivial answer thing so I guess I need to add more text to this.

This SO question helped me out with this, maybe it can help you too. I don't know if there are any other ways to add a library but this did it for me.

Community
  • 1
  • 1
Cai
  • 5,063
  • 3
  • 18
  • 23