Facebook Sdk Android Error Building

32,240

Solution 1

After digging into gradle, I came up with following solution.

Key is to exclude facebook-android-sdk required by react-native-fbsdk and pull in desired (working) version on facebook-android-sdk module - preferably without modifying anything in node_modules folder.

Fortunately, gradle offers this.

// android/app/build.gradle

dependencies {
    compile(project(':react-native-fbsdk')){
      exclude(group: 'com.facebook.android', module: 'facebook-android-sdk')
    }
    compile "com.facebook.android:facebook-android-sdk:4.22.1"
}

Solution 2

Apparently facebook has updated their sdk yesterday and the latest (4.23.0) sdk may have a bug or something.

You can resolve this by Changing your node_modules\react-native-fbsdk\android\build.gradle from:

compile('com.facebook.android:facebook-android-sdk:4.+')

To:

compile('com.facebook.android:facebook-android-sdk:4.22.1')

I'm no gradle guy so if someone knows of a better way of forcing the version from parent gradle.build, please comment and I'll update the answer.

** EDIT **

@Andreyco managed to solve this without changing node_modules. You can scroll down to his answer or click here.

Also, as notified by @JuanJoseTugores there's a pull request in react-native-fbsdk waiting to be approved, so you can check the bug's progress and be notified when it's resolved.

** Another Update **
Facebook closed the bug that was opened for them regarding this issue, saying they fixed the sdk. So now all the workarounds can be removed.

Apparently FB still not solved this. We just upgraded to RN 0.44 & FB 0.6.0

Solution 3

I was able to resolve this without modifying files under node_modules/.... I upgraded our react-native-fbsdk version to 0.6.0 and then add this to our application's build.gradle file to pin facebook-android-sdk at version 4.22.1:

project(':react-native-fbsdk') {
    configurations.all {
        resolutionStrategy {
            force 'com.facebook.android:facebook-android-sdk:4.22.1'
        }
    }
}

configurations.all {
    resolutionStrategy {
        force 'com.facebook.android:facebook-android-sdk:4.22.1'
        ...
    }
}

Edit: We are building with:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    ...
}

Solution 4

this fixed for me

in android/build.gradle

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion '27.0.3'
            }
        }
    }
}

Solution 5

I just encountered this error. First, RN Facebook SDK v.0.6.0 only works for react-native >= 0.44.0, so you have to update your dependency in package.json to react-native: ^0.44.0. Then go to Android build.gradle file and make this changes: compileSdkVersion 25 and compile "com.android.support:appcompat-v7:25.0.0"

Share:
32,240

Related videos on Youtube

Luiz
Author by

Luiz

I am a passionate Computer Scientist. My main interests are web development, with emphasis on search engines and machine learning, and Internet of Things, with emphasis on agricultural automation. I also love to work with Operating Systems architectures and their subareas.

Updated on September 14, 2020

Comments

  • Luiz
    Luiz almost 4 years

    I am trying to build my react-native project and using react-native fbsdk.

    However, I get these errors:

    /home/luiz/MYP/app/node_modules/react-native-fbsdk/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:3: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
    
    /home/luiz/MYP/app/node_modules/react-native-fbsdk/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:4: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
    
    /home/luiz/MYP/app/node_modules/react-native-fbsdk/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
    
    /home/luiz/MYP/app/node_modules/react-native-fbsdk/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
    
    
    :react-native-fbsdk:processReleaseResources FAILED
    

    My current OS is Linux Elementary 0.4.1 Loki x64.

    I am using [email protected] and, because of this, [email protected].

    I've already tried:

    • cd android && ./gradlew clean

    • delete the project and re npm install it

    • and try in Android API's 23 and 24.

    • Lucas Z.
      Lucas Z. about 7 years
      I'm on the same problem bro, tested in MacOS Sierra with the same API's
    • atlanteh
      atlanteh about 7 years
      Suddenly happens to me too. RN 0.41.2 & RN-FBSDK 0.5
  • Luiz
    Luiz about 7 years
    I am using [email protected] and, because of this, [email protected]. I'll edit the question.
  • Andreyco
    Andreyco about 7 years
    Editing anything in node_modules is greatest idea ever
  • atlanteh
    atlanteh about 7 years
    Obviously you are right. This is only a workaround I found in order to immediately solve this problem. This is why I asked if someone with a better gradle understanding can solve it in the parent build.gradle which is not in node_modules
  • Andreyco
    Andreyco about 7 years
    I did manage to solve this by setting compileSdkVersion to 24 in android/app/build.gradle. Btw, were you able to complite older react-native-fbsdk (e.g. 0.5.0)? It looks like no matter what, it pulls in latest Android SDK.
  • max23_
    max23_ about 7 years
    After updated compileSdkVersion in your android/app/build.gradle file, please also make sure you have the corresponding SDK installed (Android Studio > Configure > SDK Manager > API Level).
  • Juan Jose Tugores
    Juan Jose Tugores about 7 years
    @Andreyco no, I'm not able to compile 0.5.0 anymore :/. you could always fork the project and apply this changes.
  • Andreyco
    Andreyco about 7 years
    Trying to come up with better solution, as you are suggesting. There must be a way. Looked into react-native-fbsdk source, and I think dependency on Android SDK is being specified too loose. 4+ is no way to go, imho
  • Luiz
    Luiz about 7 years
    Upgrading is a working solution. However, sometimes unapplicable.
  • Juan Jose Tugores
    Juan Jose Tugores about 7 years
    github.com/facebook/react-native-fbsdk/pulls check the latest pull request guys
  • shirbr510
    shirbr510 about 7 years
    anyone has a solution to deal with it in CI processes? (for an example, buddybuild)
  • atlanteh
    atlanteh about 7 years
    We use BuddyBuild, but we just upgraded to latest RN. However, BuddyBuild have custom scripts you can use, like the pre build script and change the data in the node_modules (sucks, yeah)
  • narayanan
    narayanan about 7 years
    A colleague of mine suggested the following (which worked for me!): Edit settings.gradle to override the location of the build.gradle for the project in node_modules by project(':react-native-fbsdk').buildFileName = "your location to the new build.gradle file". So you can make a copy of the build.gradle for react-native-fbsdk and store it outside node_modules and use that (and even check in to version control).
  • Andreyco
    Andreyco about 7 years
    @atlanteh I did manage to resolve this by adjusting gradle config only. Check out my answer if interested.
  • paynd
    paynd about 7 years
    Only project(':react-native-fbsdk') { configurations.all { resolutionStrategy { force 'com.facebook.android:facebook-android-sdk:4.22.1' } } } needed
  • Ramon Canales
    Ramon Canales about 7 years
    For some reason this is not woking for me
  • Andreyco
    Andreyco about 7 years
    Follow @atlanteh answer then. It will work for sure, until patch is published its okay to adjust node_modules imho. My answer show more general solution, applicable to similar issues
  • Belal mazlom
    Belal mazlom about 7 years
    @RamonJamOnCanales I got same issue but solved using this inside buidl.gradle configurations.all { resolutionStrategy { force 'com.facebook.android:facebook-android-sdk:4.22.1' .... } } stackoverflow.com/a/44205756/292927
  • rtcherry
    rtcherry about 7 years
    @paynd That may work for some users, however in my application it was still attempting to use the newer SDK as a dependency and as a result I needed to force it in both the react-native-fbsdk project and in my own application's configuration.
  • Rick Love
    Rick Love about 7 years
    I had to force react-native-fbsdk to version 0.5.0 and changed the above to 4.22.1 in node_modules. It was the only thing that worked. I am using React 0.42 because my other dependencies were built against react-native 0.42 (I'm using ReactXP).
  • Allloush
    Allloush over 6 years
    Thanks... That answer save my day
  • Quilty Kim
    Quilty Kim over 6 years
    it's not working for me on react-native v0.51.0 and RN-fbsdk v0.6.3: problem occurred evaluating project ':app'. > Could not find method exclude() for arguments [{group=com.facebook.android, module=facebook-android-sdk}] on project ':react-native-fbsdk' of type org.gradle.api.Project.