Search code examples
androidkotlinandroid-library

Adding external library as file in Android Studio causing dependency error


I tried to add mXparser library downloaded from here.

I have downloaded zip file and extracted java part as the separate file. I've created 'libraries' file under Project structure and pasted this library inside. Then I've added include ':libraries:mXparser' inside settings.gradle file.

After this step I clicked File -> Project Structure -> Dependencies -> + -> Module dependency and I added this library and clicked "OK".

I'm getting these errors after compilation. How to fix them?

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :libraries:mXparser. Open File Show Details

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :libraries:mXparser. Open File Show Details

Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :libraries:mXparser. Open File Show Details

Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :libraries:mXparser. Open File Show Details

Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :libraries:mXparser. Open File Show Details

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.2.51'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Solution

  • You are adding jar file wrongly. Perform below steps to add mXparser library.

    1. Download this file and extract and you will get a jar file.

    2. Copy jar file from that folder where you downloaded, and Paste it in libs folder under app folder of your project.

    3. Now paste jar file here in libs folder

    4. Once your JAR file is successfully copied to libs folder and we will add them as dependency files.

    5. Click on File > Project Structure >Select app > Dependencies Tab.

    6. Click on (+) plus button given on right side and select File Dependency.

    7. This will pop up a dialog box for selecting path. Under this open libs folder and add your Jar files one by one.

    8. Once you select Jar file then click Ok button and your Gradle will Start building.

    You can refer here for the complete tutorial.