简体   繁体   中英

How to Import Module without creating copy in Android Studio

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

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.

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')

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')

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM