How to Import Module without creating copy in Android Studio
Asked Answered
D

4

12

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

Duggins answered 4/9, 2015 at 10:20 Comment(1)
Possible duplicate of How to reference without copying a library project on Android Studio?Promissory
H
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.

Hildegard answered 9/10, 2015 at 12:1 Comment(0)
B
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')
Bellarmine answered 4/9, 2015 at 10:29 Comment(0)
L
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')
Loris answered 25/2, 2021 at 9:48 Comment(1)
Worked great, but instead of compile use implementationStaford
T
-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?

Triple answered 4/9, 2015 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.