简体   繁体   中英

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

将库添加到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)

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM