I'm using android studio 1.1.0. I've added the parse library to my project successfully in gradle. see screenshots. But when I try to import com.parse.* or type Parse and then Alt(Option) + Enter, IDE gives error. It doesn't find the library. Here is screenshot:
And here is the gradle file that doesn't have sync error. It synched successfully.
From the documentation
1.) Download latest Parse and unzip - Latest is 1.8.2
https://parse.com/downloads/android/Parse/latest
2.) Add the parse-*.jar to your app's libs folder and add the following to the gradle.build file in dependencies
dependencies {
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
}
That should work, works well for me, Android studio version - 1.1.0
In any case if it doesnt, try File-->Invalidate Caches and Restart
After studying the problem for a few days, finally I've found the reason. If I use relative path in gradle, it doesn't work. If I use absolute path it works. Here is the absolute path:
compile files('/Users/farhadrubel/AndroidStudioProjects/android/MyProject/libs/Parse-1.8.2.jar')
You can add the library with it's absolute path easily. Remove it from your gradle file (if it's already added). Then right click on the jar file inside lib. Click on Add As Library from context menu.
Related
I have imported an external jar-library find-local-devices.jar into Android Studio project. I've put it into libs folder, right-clicked and chosen Add as library, ensured about dependency in build.gradle, cleaned and built again the project - everything as described, e.g., here.
, but I cannot still use the classes from jar:
Could somebody tell me what I do wrong?
Try "Invalidate Caches and restart" on Android Studio.
EDIT :
Also try deleting you current module and everything referring to it. And add it as the official google documentation is showing you too. The image is from here : https://developer.android.com/studio/projects/android-library.html
compile fileTree(dir: 'libs', include: ['*.jar'])
try this in gradle file and rebuild
Try another way of importing jar/aar packages into Android studio.
Goto File -> New Module -> import .JAR/.AAR package -> Select file
path and say Finish.
Then add this line in Gradle.
compile project(':your_imported_file_name')
I'm working with my first project in Android Studio 2.2. When I try to Sync the project with the Gradle, it shows an error error: package org.hamcrest does not exist
Therefore I had downloaded the hamcrest.jar library and added manually it under myfirstproject\app\libs
But, I got the following error when I add hamcrest.jar to my project.
Could not find method compile() for arguments(file collection) on object of type org.gradle.api.internal.artifacts.DSL.dependencies.DefaultDependencyHandler
This is my build.gradle file
-
Have I missed anything during the installation of my Android Studio?
Or should I need to add any libraries to the project?
If needed how it is to be done?
You added that to the wrong gradle file. Read the comment in that file that says not to add app dependencies there
Open app/build.gradle and you should notice that you already have
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
So, which means you don't have to add anything else to compile any jar files.
You really should not use a Jar file, though.
Add this
testCompile 'org.hamcrest:hamcrest-library:1.3'
Hamcrest library is something that is automatically configured with Android Studio during the installation.
Here the error is due to the incomplete installation of Android Studio. That is, most of the important external packages haven't get downloaded during the installation (including hamcrest.jar).This happened may be due to the loss of network connection at the time of installation.
So the best solution is
Uninstall the Android Studio,
Delete all the belonged files (AndroidStudioProjects,.AndroidStudio2.2 and .android folders ). Don't forget to move your current project to any other folder.
Once again install the Android Studio by making sure that you have a good network connection.
Open your last project from where it was moved
Sync the project with Gradle.
See that everything works fine!
I'm a newbie to Android Studio IDE. I used to implement Android application, using Eclipse IDE. As a beginner in Android Studio, I tried this lesson from YouTube to include a external jar file to my project and use it. But unfortunately I'm unable to use that library even though the Gradle or Android build doesn't throw any error/exception when compile and run.
I've seen related questions from SO too. As an example, I've tried out things that discuss in this question.
In the build.gradle file, I used
compile files('libs/jsoup-1.7.3.jar')
and next time used
compile fileTree(dir: 'libs', include: '*.jar')
Neither work for me. After editing that build.gradle file, I used Sync Project With Gradle Files tools and also command line clean
gradlew clean
too. No error/exceptions, but when I try to write Docu... in my MainActivity class it doesn't show the import option org.jsoup.nodes, but show other imports options. What could be the mistake I've done.
There were some bug in 0.4.2 related to dependencies management, do upgrade your studio to 0.4.3 will solve your problem .
I've got problem with adding AndEngine to Google Android Studio IDE.
I downloaded AndEngine from git and extract it to the folder.
In my existing project I clicked File>Project Structure>Modeles
In middle column green plus>new module>empty module and I selected AndEngine folder
In middle column i select my project then Dependencies>green plus at right>Module Dependency and I selected AndEngineModule.
When i try to run it there are errors like this:
Gradle: error: package org.andengine.engine.camera does not exist
I did the same! I am not sure how does it work exactly. But It seems that Android Studio uses libraries 'just for source' to find the libraries and then IDE uses Gradle like external build tool.
So I have created the libs directory in my project and move *.jar files there. I have added libraries files (*.jar) into project dependencies. Than I can use org.andegine package in my project sources but I had still the error so I have added dependencies also into build.gradle.
dependencies {
compile 'com.android.support:support-v4:18.0.0'
//compile files('libs/andengine.jar') // for single file
compile fileTree(dir: 'libs', include: '*.jar') // for all files in directory
}
I'm again lost in this facebook login part for my app. Well what happen is that I downloaded the facebook SDK from the facebook site itself then used eclipse to export the project with gradle to be used for android studio. Now in the project stucture of my main app in android I imported the Module of the facebook that I converted then on dependencies I add the module dependency of facebook in my main app. Now I tried to import the facebook package and it just works fine in my MainActivity. Now after I tried to run it errors appears see screenshot:
I tried using the ./gradle clean for both projects and it cleans just fine but I get an error for the build part. I think something went really wrong after I exported the facebook project in gradle structure. How can I solve this error? Anyone encountered this?
worked for me:
drag and drop the jar file into libs of the project (click ok to copy etc..).
then right click on the jar file -> Add as library.
Then open gradle.build and change:
Before:
dependencies {
compile files('libs/android-support-v4.jar')
}
After:
dependencies {
//compile files('libs/android-support-v4.jar')
compile fileTree(dir: 'libs', include: '*.jar')
}
We encountered the exact same problem at roughly the same time, and this is how I went about resolving it in my case.
Move the Facebook SDK project to some remote location.
Create a new Android library module in the parent Gradle project. It should be setup for Gradle. Call it 'Facebook', say. Check that its Android facet is indeed a library module.
Add all the necessary source, resource, manifest, and property files to this new module in the appropriate locations.
Modify the settings.gradle file of the parent project, so that it contains include ':Facebook', ...
Add the dependency on Facebook to your main project, 'Echo', by opening its build.gradle file and adding compile project(':Facebook') to the dependencies.
Both Echo and Facebook might depend on the android support library by now; remove this dependency from your Echo project. For instance, compile fileTree(dir: 'libs', include: '*.jar', exclude: 'android-support-v4.jar'). Check the Facebook.iml file, you want the exported dependency <orderEntry type="library" exported="" name="android-support-v4" level="project" />.
Run ./gradlew clean && ./gradlew build from the parent path.
After this clean up the dependencies in Android Studio, set the absolute apk path for your Echo project in Android Studio. This might not solve everything for you but I think these were the key steps that helped me, especially step 4. All being well you'll be much closer to solving this.
You can try importing Facebook's ant build.xml some where instead and report how you get on, but I found I was getting target redeclaration errors when I already had this error to resolve.