Search code examples
androidreact-nativegradlefacebook-android-sdk

React-Native: gradlew build yields :react-native-fbsdk:lint error "libraries must use the exact same version"


I'm running ./gradlew build after adding facebook-android-sdk and I'm getting the following error. This is both on Windows and Mac, with Gradle 4.10.1.

> Task :react-native-fbsdk:lint
Ran lint on variant debug: 19 issues found
Ran lint on variant release: 19 issues found
Wrote HTML report to file:///C:/Foo/Bar/src/ReactNative/node_modules/react-native-fbsdk/android/build/reports/lint-results.html
Wrote XML report to file:///C:/Foo/Bar/src/ReactNative/node_modules/react-native-fbsdk/android/build/reports/lint-results.xml

> Task :react-native-fbsdk:lint FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-fbsdk:lint'.
> Lint found errors in the project; aborting build.

  Fix the issues identified by lint, or add the following to your build script to proceed with errors:
  ...
  android {
      lintOptions {
          abortOnError false
      }
  }
  ...

  Errors found:

  C:\Foo\Bar\src\ReactNative\node_modules\react-native-fbsdk\android\build.gradle: Error: All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 27.0.2. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:cardview-v7:27.0.2 [GradleCompatible]

Specifically, there's a compatibility issue between com.android.support:animated-vector-drawable:28.0.0 and com.android.support:cardview-v7:27.0.2. Others have fixed similar issues by changing this line in build.gradle

implementation 'com.facebook.android:facebook-android-sdk:[4,5)'

...to something like this:

implementation('com.facebook.android:facebook-android-sdk:[4,5)') {
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'appcompat-v7'
    exclude group: 'com.android.support', module: 'cardview-v7'
    exclude group: 'com.android.support', module: 'customtabs'
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'support-core-utils'
    exclude group: 'com.android.support', module: ':animated-vector-drawable'
}

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'

When I look at dependencies, they seem to be resolved correctly to 28.0.0, not 27.0.2 as indicated in the error:

./gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath
=> 
// ...
+--- com.facebook.android:facebook-android-sdk:4.40.0
|    +--- com.facebook.android:facebook-core:4.40.0
|    |    +--- com.parse.bolts:bolts-android:1.4.0
|    |    |    +--- com.parse.bolts:bolts-tasks:1.4.0
|    |    |    \--- com.parse.bolts:bolts-applinks:1.4.0
|    |    |         \--- com.parse.bolts:bolts-tasks:1.4.0
|    |    +--- com.android.support:support-annotations:27.0.2 -> 28.0.0
|    |    \--- com.android.support:support-core-utils:27.0.2 -> 28.0.0 (*)
|    +--- com.facebook.android:facebook-common:4.40.0
|    |    +--- com.facebook.android:facebook-core:4.40.0 (*)
|    |    +--- com.android.support:support-v4:27.0.2 -> 28.0.0
|    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    +--- com.android.support:support-media-compat:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    \--- com.android.support:versionedparcelable:28.0.0 (*)
|    |    |    +--- com.android.support:support-core-utils:28.0.0 (*)
|    |    |    +--- com.android.support:support-core-ui:28.0.0 (*)
|    |    |    \--- com.android.support:support-fragment:28.0.0 (*)
|    |    +--- com.android.support:appcompat-v7:27.0.2 -> 28.0.0 (*)
|    |    +--- com.android.support:cardview-v7:27.0.2 -> 28.0.0
|    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    +--- com.android.support:customtabs:27.0.2 -> 28.0.0
|    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:interpolator:28.0.0 (*)
|    |    |    +--- com.android.support:collections:28.0.0 (*)
|    |    |    \--- com.android.support:support-core-ui:28.0.0 (*)
|    |    \--- com.google.zxing:core:3.3.0

Any idea what is going on here?

edit Other things that don't work:

  • adding the lintOptions to build.gradle as suggested in the error message has no effect.
  • clearing the $HOME/.gradle cache and the ReactNative/android/.gradle cache
  • Upgrading to gradle 4.10.3
  • adding disable "GradleDependency" in lintOptions
  • flagging lines with //noinspection GradleDependency
  • lintOptions.tasks.lint.enabled = false

Solution

  • This seems to disable the error in lint if I put it in app/build.gradle:

    allprojects {
        // ...
        afterEvaluate {
            if (getPlugins().hasPlugin('android') ||
                getPlugins().hasPlugin('android-library')) {
    
                println name // for debugging
    
                configure(android.lintOptions) {
                     abortOnError false
                }
            }
         }
    }
    

    Source: How to disable lint abortOnError in Android Gradle Plugin from top level of multi project directory