Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libs folder doesn't work in android studio

I am using the mac version of android studio 1.2 Beta 2, built on April 7, 2015. Gradle version 2.2.1 and Gradle plug-in version 1.1.0.

After I create a new project, The following code exist by default in my app/build.gradle file.

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

It means that any jar file I add to the app/libs directory should be loaded to my project, right? However, when I add my Parse-1.9.0.jar to the app/libs, it is not loaded. I failed to use the code from the API in MainActivity.java.

I got it working by right click Parse-1.9.0.jar -> Add As Library... The app/build.gradle became:

...
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/Parse-1.9.0.jar')
}

I am confused of why. Shouldn't compile fileTree() include all the jar files? Why do I need to do the additional step?

The Parse-1.9.0.jar file I downloaded is from: https://parse.com/apps/quickstart#parse_data/mobile/android/native/existing

Thanks

like image 213
Xi Wei Avatar asked Apr 11 '15 02:04

Xi Wei


2 Answers

Adding libraries to Android Studio 1.2

(1) Select the Packages view for the project (2) Drag your library (jar) file into the "libs" folder in Packages view (3) Right-click the newly added jar file - and select "Add as library" in the dialogue - Then click OK in next dialogue (Gradel Sync will start)

like image 161
jpd Avatar answered Oct 09 '22 01:10

jpd


For every change you make to your libs folder (add, remove .jar) you need to sync your gradle files. Jar file libraries are not discovered automatically by AS - as it was with Eclipse.

like image 44
Mimmo Grottoli Avatar answered Oct 09 '22 01:10

Mimmo Grottoli