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
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With