Android Studio 0.6.0 Facebook SDK Import - android

I followed using facebook sdk in android studio and since I have a libs folder under my 'app' folder, I tried to import it in there by selecting libs and File-->Import Module. I get this:
I'm able to run ProfilePictureSample, which relies on the facebook module, but not app. Logcat says " java.lang.NoClassDefFoundError: com.facebook.android.Facebook" even though I can verify it's there. I get this messsage even after cutting the facebook module and pasting it into the libs folder. Here is a snippet of app-->build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/Parse-1.5.0/Parse-1.5.0.jar') ...

you don't add it under the libs folder, it can be at the same level as "app". In app/build.gradle, add this line: "compile project(':facebook')"

Related

android studio gradle dependencies fails with no error

I'm using the gradle build script, in android studio to fetch the Parse android SDK, as follow:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
}
The build process succeeds with no errors, yet , when I the to import com.parse.Parse; I get cannot resolve symbol parse.
To my understanding, that build script was supposed to download the Parse SDK from a maven repository, and build it, or otherwise to fail.
Where do I have wrong?
Check Parse's Android Studio guide again, you'll see this:
Step 1 instructs you to download the SDK.
Step 2 asks you to first put Parse-*.java to the project's libs folder, and then add the script you've shown in your question into build.gradle. Notice that the library pulled from maven is just an auxiliary library, not the Parse library itself. This is why Android Studio cannot find the Parse class.

Adding Parse-1.8.0 to Android Studio 1.0.1 (Or any .zip file)

So there seems to be a few threads that attempt to explain how to add .zip files to android studio but I am making no progress. I am migrating from eclipse so perhaps that is why I am so incompetent in figuring out how to perform this task. Can someone please explain how to add external libraries to Android Studio v1.0.1? In eclipse it was simply importing jar/zip and done.
I was in the same situation, trying to integrate Parse 1.8 with Android Studio 1.0.2.
On Parse's instruction page, it simply tells you to import the library into Android studio, which isn't too detailed. Here is how I solved this problem.
Choose to import from a "Non Android Studio Project", right when Android Studio starts.
When it asks you to choose the project, give the path, on Windows e.g.C:/path/to/parsesdk/. On *nix systems, it should be to where you have extracted to it, /home/user/path/to/parsesdk.
After you choose the path, Android Studio will import the project accordingly.
Click on the Application root folder (the top most folder in the folder hierarchy to the left), right click > New > Package > and add it under the src folder, name is libs.
Copy paste the jar to the libs folder (I only copied the jar file, as I didn't need the other extra material)
Right click on the jar, there should be an option labeled as "Add as library" towards the bottom, click on that.
Android Studio will automatically add the following to the build.gradle file.
compile files('src/libs/Parse-1.8.0.jar')
Once the above step is completed, click on File > Project Structure.
On the left, there should be a section called "Modules", click on the "Dependencies" tab on the top.
Click the green "+" sign > Module Dependency
Select the module from the list.
Last thing, in the build.gradle file for the "ParseStarterProject" module, if there is a red line under the classpath, change it to the following
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
After completing this step, I was able to successfully build the app.
Hope this helps :)
If you are using gradle with android studio (which is the preferred way now) you can include jars in a folder using this code snipet from my build.gradle.
buildscript {
repositories {
flatDir { dirs 'c:\\path\\to\\folder' }
mavenCentral()
}
}
Or by including a single file in depencies like below.
dependencies {
compile fileTree(dir: 'a-folder-in-root-of-project', include: 'a_jar.jar')
}
This is the only way it worked for me :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//Parse
compile 'com.parse.bolts:bolts-android:1.+'
compile files('libs/Parse-1.9.2/Parse-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseCrashReporting-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseFacebookUtilsV3-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseFacebookUtilsV4-1.9.2.jar')
compile files('libs/Parse-1.9.2/bolts-android-1.2.0-javadoc.jar')
compile files('libs/Parse-1.9.2/bolts-android-1.2.0.jar')
}
OR
//Parse
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs/Parse-1.9.2', include: 'Parse-*.jar')
compile fileTree(dir: 'libs/Parse-1.9.2', include: 'ParseCrashReporting-*.jar')

How to Import jar file into an Android project?

I am trying to use the loopj library in my Android project. In the project home page it says "Download the latest .jar file from github and place it in your Android apps libs folder". I did that!
As indicated in the documentation of the loopj I try to import it using the following
import com.loopj.android.http;
and nothing happens. It is not even coming up in intellisense.
Am I doing anything wrong?
in the build.gradle file add your jar such as below then rebuild.
dependencies {
compile files('libs/android-async-http-1.4.4.jar')
}
into the build.gradle file add the following::
dependencies {
// ... other dependencies
compile files('libs/<your jar's name here>')
}
Rebuid your project or Run ./gradlew assemble. This should compile the project with the library.
To let the Android Studio load all of your jar files by itself automatically, just write this line in the dependency section
compile fileTree(dir: 'libs', include: ['*.jar'])
This will help android studio to load all of your jar files available in libs folder.

Android Studio and AndEngine - package does not exist

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
}

Gradle error: package com.facebook does not exists for android studio

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.

Categories

Resources