libs folder doesn't work in android studio
Asked Answered
H

4

17

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

Handbreadth answered 11/4, 2015 at 2:1 Comment(0)
G
2

I don't know 'why' is fileTree option not working. But surprisingly, wildcard approach works.

dependencies {
    compile files('libs/*.jar')
}
Granular answered 22/7, 2015 at 1:36 Comment(0)
R
5

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)

Roentgen answered 21/4, 2015 at 12:50 Comment(2)
Thank you for the replay. I did that already as I mentioned in my question. The question I am asking is why do we need compile files('libs/Parse-1.9.0.jar') when there is already compile fileTree(dir: 'libs', include: ['*.jar']) in placeHandbreadth
yes after selecting pakages view I came to know libs folder location is wrong.Fatalism
G
5

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.

Gab answered 22/7, 2015 at 9:35 Comment(0)
G
2

I don't know 'why' is fileTree option not working. But surprisingly, wildcard approach works.

dependencies {
    compile files('libs/*.jar')
}
Granular answered 22/7, 2015 at 1:36 Comment(0)
F
1

implementation fileTree(dir: "libs", include: ["*.jar"])

Fondly answered 14/9, 2021 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.