11

I am using Android Studio 1.3.1 and trying to add library module to an existing android application. The library module is available in a git repository. I am able to import the module, but it creates a copy inside the existing app. Hence I am not able to pull the updates in the module.

I am sure there is a way to import external libraries from an existing Android project in studio.

I found the below stackoverflow posts related to my doubt -

  1. How to import a Module on Android Studio 0.5.1?
  2. Android Studio 0.8.1 Creating Modules without copying files?

Both seem not to work for me. I also found couple of comments from other users saying it is also not working for them in the latest version of studio.

Here are the things that I tried

// in settings.gradle
include ':libraryName'
project(':libraryName').projectDir=new File('/path/to/library')

// in build.gradle
compile project(':libraryName')

Also I tried using this this url

Any help is appreciated. Thanks

Community
  • 1
  • 1
Nirmalkumar
  • 251
  • 3
  • 12
  • Possible duplicate of [How to reference without copying a library project on Android Studio?](https://stackoverflow.com/questions/24494105/how-to-reference-without-copying-a-library-project-on-android-studio) – TT-- Jan 29 '19 at 03:09

4 Answers4

17

You were on the right track. Just make sure your library is inside one folder then you can direct the library path like this..

Inside settings.gradle

include ':libraryName'
project (":libraryName").projectDir = new File("../FolderName/libraryName")

if your library is inside 2 folders then direct the path like this...

include ':libraryName'
project (":libraryName").projectDir = new File("../../FolderName/libraryName")

This allowed me to use the library without making a duplicate.

RyallitZ
  • 189
  • 6
3

Is your path relative or absolute there?

Try this if you want to reference the other module relative to the current project:

    include ':libraryName'
    project(':libraryName').projectDir = new File(rootProject.projectDir, '../path/to/library')
Dean Wild
  • 5,886
  • 3
  • 38
  • 45
1

Set the projectDir and by setting the rootProject.name it will also show up in your IDEs Project pane:

// in settings.gradle
include ':app'
rootProject.name = "Project name"
include ':libraryName'
project (":libraryName").projectDir = new File("../path/to/library")
// in build.gradle
compile project(':libraryName')
Kubus
  • 677
  • 6
  • 18
-3

Have you tried creating a folder 'libs' under your project and copying the .jar file to that folder and try compile the libs folder? That seems to normally work for me. I think it was the first solution on this question

How to import a Module on Android Studio 0.5.1?

Community
  • 1
  • 1
user2132226
  • 85
  • 1
  • 1