Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3: how do I import a source code library into a project

The build.gradle in the appfolder contains the following code:

dependencies {
    ...
    compile project(':sclibrary')
}

The settings.gradle file in the project folder contains:

include ':app', ':sclibrary'
project(':sclibrary').projectDir = new File(rootProject.projectDir, '../sclibrary4')

When I synchronize my project I get an error that says "Missing dependencies: unable to find module with Gradle path ':sclibrary' (needed by module 'app'.)"

EDIT:

"sclibrary4" is located in the folder as the "sc" and "ScLite" applications; these applications use common code located in "sclibrary4" file structure

When I try to use the "File>New>Import Module" command, I get the error message "This location is already imported" although

enter image description here

and

enter image description here

like image 782
ema3272 Avatar asked Dec 17 '17 15:12

ema3272


People also ask

How do I import library to Android?

Click on “Import Existing Project“. Step 2: Select the desired library and the desired module. Then click finish. Android Studio will import the library into your project and will sync Gradle files.

How can I use downloaded code in Android Studio?

Importing into Android StudioOpen Android Studio and select Open an Existing Android Studio Project or File, Open. Locate the folder you downloaded from Dropsource and unzipped, choosing the “build. gradle” file in the root directory. Android Studio will import the project.


1 Answers

Something like this can be fixed with:

  • remove project dependency from settings.gradle file
  • remove dependency from build.gradle
  • gradle sync
  • Android Studio should show an info that a dependency has been removed
  • add dependencies again

This worked for me on several occasions, e.g. with Android Studio 3.1.2

like image 90
Boni2k Avatar answered Oct 09 '22 22:10

Boni2k