Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jar files in libs folder are not used in Android Gradle build

i just started to play with the gradle build system for Android.

However i'm not able build one of my projects. It depends on a jar in the libs/ folder.

Doing gradle build fails in the compileDebug task because all of the classes from the jar file are missing.

It is a library project! Here is my build.gradle file:

buildscript {     repositories {         mavenCentral()     }     dependencies {         classpath 'com.android.tools.build:gradle:0.2'     } }  apply plugin: 'android-library'  android {     target='android-16'     sourceSets {         main {             manifest {                 srcFile 'AndroidManifest.xml'             }             java {                 srcDir 'src'             }             res {                 srcDir 'res'             }             assets {                 srcDir 'assets'             }             resources {                 srcDir 'src'             }         }     } } 

Am i missing something obvious?

Goddchen

like image 672
Goddchen Avatar asked Oct 25 '12 14:10

Goddchen


People also ask

Where does gradle Place jar files?

The Jar is created under the $project/build/libs/ folder.


2 Answers

just found the answer myself:

Seems like the current version of the Android Gradle plugin doesn't look for jars in the libs/ folder. So you have to add them yourself:

dependencies {     compile files('libs/mylib.jar') } 

or

dependencies {     compile fileTree(dir: 'libs', include: '*.jar') } 

Place this within the android namespace like this:

android {     target = "android-15"      dependencies {         compile fileTree(dir: 'libs', include: '*.jar')     }  } 
like image 110
Goddchen Avatar answered Sep 22 '22 07:09

Goddchen


Just in case none of the solutions worked for you, you may want to try to provide the path to the *.jar manually:

compile files('../<your-library-folder>/<your-library>.jar') 

The '../' part means that Gradle will search for the library starting from the root projects folder (not app module).

like image 25
Paul Freez Avatar answered Sep 20 '22 07:09

Paul Freez