Lobstw
Lobstw

Reputation: 499

How to use imported library project in Android Studio?

I imported the library project following this guide: https://stackoverflow.com/a/20497933 and now I have a libs folder with my required library.

But how do I use it in my code. I can't import com.github.whateverlibrary and I can't use com.mypackagename.whateverlibrary.

How do I reference this local library in my project?

Edit:

My settings.gradle file:

include ':libs:MyLibrary'

My app.gradle file:

compile fileTree(include: ['MyLibrary'], dir: 'libs')

Upvotes: 1

Views: 766

Answers (2)

Lobstw
Lobstw

Reputation: 499

Somehow got it working. Exact steps:

  1. Download library folder from Github for the thing you want to import. For example: testgithublibrary\library
  2. Place this folder in project root under libs\ so the full path would be AndroidStudioProjects\MyPackage\libs and rename it to something else e.g. testlocallibrary
  3. Add compile project(':libs:testlocallibrary') to app.gradle
  4. Add include ':libs:testlocallibrary' to settings.gradle in root
  5. Sync
  6. Reference gradle with how it would have been referenced if you had got it online. Or you can just open up the library folder and see how it is: e.g. testlocallibrary\~java\com\example\mymodule\...

Upvotes: 0

Sakchham
Sakchham

Reputation: 1739

To add imports from a library listed as a dependency, use the fully qualified names for the classes. For example to import from https://github.com/bumptech/glide you will use the names as is in the library without any modifications such as adding com.github or com.yourpackagename
To import Glide to your class you would use

import com.bumptech.glide.Glide;

see sample projects for better understanding

Upvotes: 1

Related Questions