1

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')
Community
  • 1
  • 1
Lobstw
  • 489
  • 3
  • 18

2 Answers2

1

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

Sakchham
  • 1,689
  • 12
  • 22
  • Writing this in my class will download and import from bumptech.com? Correct? I want to use the library that I have downloaded and edited locally. – Lobstw Jul 04 '16 at 19:06
  • no it wont download, as you mentioned in the question that you've already added the project as a dependency, this soulution would just import. – Sakchham Jul 04 '16 at 19:08
  • This answers the question. The reference should be the same. – Lobstw Jul 04 '16 at 23:10
0

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\...
Lobstw
  • 489
  • 3
  • 18