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

10,164

Solution 1

We encountered the exact same problem at roughly the same time, and this is how I went about resolving it in my case.

  1. Move the Facebook SDK project to some remote location.

  2. 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.

  3. Add all the necessary source, resource, manifest, and property files to this new module in the appropriate locations.

  4. Modify the settings.gradle file of the parent project, so that it contains include ':Facebook', ...

  5. Add the dependency on Facebook to your main project, 'Echo', by opening its build.gradle file and adding compile project(':Facebook') to the dependencies.

  6. 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" />.

  7. 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.

Solution 2

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')
}
Share:
10,164
KaHeL
Author by

KaHeL

Updated on June 14, 2022

Comments

  • KaHeL
    KaHeL almost 2 years

    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:

    enter image description here

    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?

    • Ken
      Ken almost 11 years
      I can't help yet, but you need to add the contents of your build.gradle file to your question.
  • KaHeL
    KaHeL almost 11 years
    I see, well I believe that this is the steps I've been looking for this past few days. Anyway as for this one I already made a solution for this since the only things I want to work with facebook with this project is the login, get graph, logout. Here's the steps I made. 1st copy all the Activity files I needed on facebook SDK. 2nd is to manually create a path to contain this activity on java folder where I will get com.facebook.android where I used 3 folders. then I can now import all the activities. Well I just don't know the drawbacks but it works! :)