Crayon
Crayon

Reputation: 291

How do I reference a library on Android Studio?

I am trying to build an Xposed module but I'm stuck at referencing the library.

Library is inside app/lib because the ones in libs are included not referenced, my build.gradle looks like this:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'

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

configurations {
    provided
}

dependencies {
    provided 'lib/XposedBridgeApi-54.jar'
}

sourceSets {
    main {
        compileClasspath += configurations.provided
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

I get this error:

Error:(20, 0) The description lib/XposedBridgeApi-54.jar is invalid

It looks like it can't find the library because if I try to change the name to something that doesn't exists it gives the same error. I tried:

provided 'XposedBridgeApi-54.jar'
provided 'lib/XposedBridgeApi-54.jar'
provided 'app/lib/XposedBridgeApi-54.jar'

First one placing library in the root folder and nothing works.

This is how the directory structure looks (can't post pictures):

https://i.sstatic.net/jmN3B.png

Official documentation says to use:

dependencies {
    compile project(':libraries:lib1')
}

but I don't know what to use with this format.

Upvotes: 0

Views: 640

Answers (1)

Crayon
Crayon

Reputation: 291

I found the solution for this checking other github repositories, looks like most of people don't use Android Studio.

The key is don't add anything on projectName/build.gradle but add at the end of projectName/app/src/build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    provided files('lib/XposedBridgeApi-54.jar')
}

remember to not put it on libs

Reference

Upvotes: 2

Related Questions