Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

com.android.support:support-v4 version conflict #1532

Closed
rexlow opened this issue May 2, 2018 · 23 comments
Closed

com.android.support:support-v4 version conflict #1532

rexlow opened this issue May 2, 2018 · 23 comments

Comments

@rexlow
Copy link

rexlow commented May 2, 2018

Actual behaviour

I am using this library together with react-native-firebase. Installation for iOS with pods went fine, it was a disaster on Android. I followed the official installation instruction for both automatic linking and manual linking and both failed with this error.

Android dependency 'com.android.support:support-v4' has different version for the compile (26.1.0) and runtime (27.1.0) classpath. You should manually set the same version via DependencyResolution

I tried to mitigate this error with the command below (similar issue on Flutter), but it just gets worse.

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                && !details.requested.name.contains('multidex') ) {
                        details.useVersion "26.1.0"
            }
        }
    }
}

I've reviewed all related files and do not see any that specifies 26.1.0. Here's my configs if they help.

Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.smarthome">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

      <!-- RNFirebase messaging -->
      <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
      </service>
      <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
        <intent-filter>
          <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
      </service>
      <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
    </application>

</manifest>

Project Level Gradle File

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.1.2'
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        google()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }

    }
}

App Level Gradle File

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.smarthome"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation project(':react-native-camera')
    implementation(project(':react-native-firebase')) {
        transitive = false
    }
    implementation "com.google.firebase:firebase-core:15.0.0"
    implementation "com.google.android.gms:play-services-base:15.0.0"
    
    implementation "com.google.firebase:firebase-auth:15.0.0"
    implementation "com.google.firebase:firebase-database:15.0.0"
    implementation "com.google.firebase:firebase-storage:15.0.0"
    implementation "com.google.firebase:firebase-messaging:15.0.0"
    implementation "me.leolin:ShortcutBadger:1.1.21@aar"
    
    implementation project(':react-native-fs')
    implementation project(':react-native-vector-icons')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:23.0.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

MainApplication.java

package com.smarthome;

import android.app.Application;

import com.facebook.react.ReactApplication;
import org.reactnative.camera.RNCameraPackage;
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.storage.RNFirebaseStoragePackage;
import io.invertase.firebase.database.RNFirebaseDatabasePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

import com.rnfs.RNFSPackage;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new RNCameraPackage(),
            new RNFirebasePackage(),
            new RNFirebaseAuthPackage(),
            new RNFirebaseStoragePackage(),
            new RNFirebaseDatabasePackage(),
            new RNFirebaseMessagingPackage(),
            new RNFirebaseNotificationsPackage(),
            new VectorIconsPackage(),
            new RNFSPackage()
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

Environment

  • Node.js version: 8.3.0
  • React Native version: 0.54.2

react-native-camera

Version: 1.1.2

@jgfidelis
Copy link
Collaborator

change implementation project(':react-native-camera') to:

implementation (project(':react-native-camera')) {
        exclude group: "com.android.support"
    }
implementation "com.android.support:exifinterface:+"
  implementation "com.android.support:support-annotations:+"
  implementation "com.android.support:support-v4:+"

@sibelius sibelius closed this as completed May 2, 2018
@rexlow
Copy link
Author

rexlow commented May 2, 2018

@jgfidelis As soon as I rebuild, it gives another error (AAPT2) and a few other errors.

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugResources'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
	at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
	at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
	at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
	at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.gradle.tooling.BuildException: Failed to process resources, see aapt output above for details.
	at com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.invokeAaptForSplit(LinkApplicationAndroidResourcesTask.java:512)
	at com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.doFullTaskAction(LinkApplicationAndroidResourcesTask.java:249)
	at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
	at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
	at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
	at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
	... 32 more
	Suppressed: java.lang.RuntimeException: Some file processing failed, see logs for details
		at com.android.builder.internal.aapt.QueuedResourceProcessor.waitForAll(QueuedResourceProcessor.java:121)
		at com.android.builder.internal.aapt.QueuedResourceProcessor.end(QueuedResourceProcessor.java:141)
		at com.android.builder.internal.aapt.v2.QueueableAapt2.close(QueueableAapt2.java:104)
		at com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.doFullTaskAction(LinkApplicationAndroidResourcesTask.java:293)
		... 48 more
Caused by: com.android.ide.common.process.ProcessException: Failed to execute aapt
	at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809)
	at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797)
	at com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.invokeAaptForSplit(LinkApplicationAndroidResourcesTask.java:491)
	... 49 more
Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
	at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
	at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)
	at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
	at com.android.builder.internal.aapt.AbstractAapt.link(AbstractAapt.java:34)
	at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:807)
	... 51 more
Caused by: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
	at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
	at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:462)
	at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
	at com.android.builder.internal.aapt.v2.QueueableAapt2.lambda$makeValidatedPackage$1(QueueableAapt2.java:166)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	... 1 more
Caused by: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
	at com.android.builder.png.AaptProcess$NotifierProcessOutput.handleOutput(AaptProcess.java:443)
	at com.android.builder.png.AaptProcess$NotifierProcessOutput.err(AaptProcess.java:395)
	at com.android.builder.png.AaptProcess$ProcessOutputFacade.err(AaptProcess.java:312)
	at com.android.utils.GrabProcessOutput$1.run(GrabProcessOutput.java:104)

screen shot 2018-05-02 at 9 38 45 pm

@sibelius
Copy link
Collaborator

sibelius commented May 2, 2018

disable appt2 for now, it is not supported by react-native yet

@rexlow
Copy link
Author

rexlow commented May 2, 2018

@sibelius I have disabled it, but another error pops up. Perhaps it has to do with the sdk version I'm on?

Process 'command '/Users/rexlow/Library/Android/sdk/build-tools/27.0.3/aapt'' finished with non-zero exit value 1

I am not sure which sdk version should I use (coming from iOS), here's the configuration.

    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    ...

    dependencies {
        ...
        implementation "com.android.support:exifinterface:+" . <-- mixing versions can lead to runtime crashes
        implementation "com.android.support:appcompat-v7:23.0.1"
        ...
    }

@sibelius
Copy link
Collaborator

sibelius commented May 2, 2018

@code-by
Copy link

code-by commented May 2, 2018

Same error, my app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.rn055"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    // compile project(':react-native-camera')
implementation (project(':react-native-camera')) {
        exclude group: "com.android.support"
    }
implementation "com.android.support:exifinterface:+"
  implementation "com.android.support:support-annotations:+"
  implementation "com.android.support:support-v4:+"

    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"
}


// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

got this

Loading dependency graph, done.
warning: the transform cache was reset.
bundle: Writing bundle output to: /~/rn055/RN055/android/app/build/intermediates/assets/release/index.android.bundle
bundle: Done writing bundle output

/~/.gradle/caches/transforms-1/files-1.1/appcompat-v7-23.0.1.aar/63be421add3cb80ad7738b9c93904cf8/res/values/values.xml:113:5-69: AAPT: error: resource android:attr/fontVariationSettings not found.
    
/~/.gradle/caches/transforms-1/files-1.1/appcompat-v7-23.0.1.aar/63be421add3cb80ad7738b9c93904cf8/res/values/values.xml:113:5-69: AAPT: error: resource android:attr/ttcIndex not found.
    
/~/rn055/RN055/android/app/build/intermediates/incremental/mergeReleaseResources/merged.dir/values/values.xml:187: error: resource android:attr/fontVariationSettings not found.
/~/rn055/RN055/android/app/build/intermediates/incremental/mergeReleaseResources/merged.dir/values/values.xml:187: error: resource android:attr/ttcIndex not found.
error: failed linking references.

> Task :app:processReleaseResources
Failed to execute aapt
com.android.ide.common.process.ProcessException: Failed to execute aapt

@rexlow
Copy link
Author

rexlow commented May 2, 2018

@code-by Glad to know I am not alone.

@sibelius The example you provided earlier was not helpful. I have tried linking manually before opening this issue. Please reopen this issue.

@code-by
Copy link

code-by commented May 2, 2018

@rexlow
I have found solution
crosswalk-project/cordova-plugin-crosswalk-webview#205 (comment)
adding to end of build.gradle

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
    }
}

@jgfidelis
Copy link
Collaborator

I will reopen to see if anyone helps you but this is not a RNCamera issue, but an issue on your project. We use RNCamera and Firebase on our projects.

apply plugin: "com.android.application"
//apply plugin: "com.google.firebase.firebase-perf"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "..."
        minSdkVersion 19
        targetSdkVersion rootProject.ext.targetSdkVersion
        // for fast lane https://github.com/fastlane/fastlane/issues/878#issuecomment-261954917
        versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 525
        versionName "2.0.0"
        multiDexEnabled true
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }

    signingConfigs {
        release {
            ...
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
        debug {
            applicationIdSuffix ".debug"
        }
    }

    dexOptions {
        javaMaxHeapSize "2g"
    }
}

buildscript {
  ext.googleServicesVersion = '12.0.0'

  repositories {
    maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
    // These docs use an open ended version so that our plugin
    // can be updated quickly in response to Android tooling updates

    // We recommend changing it to the latest version from our changelog:
    // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
    classpath 'io.fabric.tools:gradle:1.+'
  }
}

dependencies {
    implementation project(':react-native-background-fetch')
    implementation project(':react-native-fetch-blob')
    implementation project(':react-native-text-input-reset')
    implementation(project(':react-native-maps')){
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation(project(':react-native-firebase')) {
        transitive = false
        // very important - dedupe deps
        exclude group: "com.google.android.gms"
        exclude group: "com.google.firebase"
    }
    implementation project(':react-native-view-shot')
    implementation project(':react-native-share')
    implementation (project(':react-native-device-info')) {
        exclude group: "com.google.android.gms" // very important
    }
    implementation(project(':react-native-google-analytics-bridge')) {
        exclude group: "com.google.android.gms" // very important
    }
    implementation project(':react-native-fs')
    implementation project(':react-native-image-resizer')
    // For animated GIF support
    implementation 'com.facebook.fresco:animated-gif:1.3.0'
    implementation project(':rn-splash-screen')
    implementation(project(":react-native-google-signin")){
        exclude group: "com.google.android.gms" // very important
    }
    implementation project(':react-native-fbsdk')
    implementation project(':react-native-calendar-events')
    implementation (project(':react-native-camera')) {
        exclude group: "com.google.android.gms"
        exclude group: "com.android.support"
    }
    implementation project(':react-native-fabric')
    implementation(project(":react-native-visa-checkout")){
        exclude group: "com.google.android.gms"
        exclude group: "com.android.support"
    }
    implementation project(':react-native-device-brightness')
    implementation project(':react-native-svg')
    implementation project(':react-native-version-number')
    implementation project(':react-native-i18n')
    implementation project(':react-native-linear-gradient')
    implementation project(":react-native-shared-preferences")
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.0.2"
    implementation 'com.android.support:design:27.0.2'
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.android.support:multidex:1.0.1'
    implementation "com.android.support:exifinterface:27.0.2"

    implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }
    implementation ("com.google.android.gms:play-services-auth:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.android.gms:play-services-ads:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.android.gms:play-services-vision:$googleServicesVersion") {
        force = true;
    }

    // Firebase
    implementation ("com.google.android.gms:play-services-base:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.android.gms:play-services-maps:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-core:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-config:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-auth:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-database:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-storage:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-messaging:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-crash:$googleServicesVersion") {
        force = true;
    }
    //implementation ("com.google.firebase:firebase-perf:$googleServicesVersion") {
    //    force = true;
    //}
    //implementation ("com.google.firebase:firebase-plugins:$googleServicesVersion") {
    //    force = true;
    //}
    implementation ("com.google.firebase:firebase-ads:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-firestore:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-invites:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.firebase:firebase-analytics:$googleServicesVersion") {
        force = true;
    }
    // Google Analytics
    implementation ("com.google.android.gms:play-services-analytics:$googleServicesVersion") {
        force = true;
    }
    implementation ("com.google.android.gms:play-services-tagmanager:$googleServicesVersion") {
        force = true;
    }
    //compile(name: 'tsbackgroundfetch', ext: 'aar')
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
}

repositories {
  maven { url 'https://maven.fabric.io/public' }
  //flatDir {
  //  dirs "../../node_modules/react-native-background-fetch/android/libs"
  //}
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

@rexlow
Copy link
Author

rexlow commented May 2, 2018

@code-by and @jgfidelis both your suggestions was very helpful! Am finally able to run after adding

multiDexEnabled true and implementation 'com.android.support:multidex:1.0.1'

to the build.gradle file

@rexlow rexlow closed this as completed May 2, 2018
@code-by
Copy link

code-by commented May 2, 2018

@rexlow glad to hear, but I'm changing nothing about multidex:1.0.1 in my project files )

@ducpt2
Copy link

ducpt2 commented May 3, 2018

@sibelius i follow you suggest and can view camera, but scan barcode not work at all. I check many issue about barcode, but no luck? I think my issue is i update Android studio to new version.
Any help pls?

@brickolicious
Copy link

brickolicious commented May 3, 2018

build.gradle

multidex true

compile ("com.android.support:support-v4:26.0.1") {
force = true //<-- force dependency resolution to 26.0.1 in my case
}

This resolved it for me

@ducpt2
Copy link

ducpt2 commented May 4, 2018

@brickolicious do you test barcode scan? Does it work?

@brickolicious
Copy link

I scan QR succesfully, haven't tried barcodes

@Mian007
Copy link

Mian007 commented May 15, 2018

i am facing the problem
Execution failed for task ':react-native-camera:compileDebugJavaWithJavac'.
after add these two solutions to my app/build dependecies section
implementation 'com.android.support:multidex:1.0.1'; compile ("com.android.support:support-v4:26.0.1") { force = true //<-- force dependency resolution to 26.0.1 in my case }

@kkusanagi
Copy link

kkusanagi commented May 18, 2018

Thanks to @jgfidelis . I just change as below and it work.

//change this under dependencies tree
implementation (project(':react-native-camera')) {
        exclude group: "com.google.android.gms"
        exclude group: "com.android.support"
    }

//add this in the bottom
configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
    }
}

@AndreiCalazans
Copy link
Collaborator

A mix of things worked for me.

  react: 16.3.1 => 16.3.1
  react-native: 0.55.1 => 0.55.1

Add the following to your dependecies inside android/app/build.gradle

compile ("com.android.support:support-v4:26.0.1") {
        force = true //<-- force dependency resolution to 26.0.1 in my case
    }

Also make sure to update android/build.gradle to use gradle 3 and add google

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        google()
    }
}

Don't forget to also to update the distribuitionUrl in android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

@saivamsid
Copy link

@AndreiCalazans Thanks! it worked.

@pmiri
Copy link

pmiri commented Jun 19, 2018

I added these changes and can get the build to compile. But when launching the debugger, the app crashes on right as it starts up. Is there possibly an SDK mismatch or something?

@Aung-Myint-Thein
Copy link

I was using Firebase and React Native Camera. Then the app is crashing. After several hours of investigation, I found out that React Native Component <Switch> is the culprit. Then I had to downgrade to com.android.support:support-v4:26.0.1 in app/build.gradle as @AndreiCalazans suggested.

So, if anyone of you is facing the same problem, maybe this will help. All the best in coding!

As a side note, React Native libraries' dependencies are getting messier and messier :(

@youngjuning
Copy link

this can solve my trouble

implementation (project(':react-native-camera')) {
    // http://t.cn/EwxC1tr
    exclude group: "com.android.support"
}

@mattgle
Copy link

mattgle commented Jan 2, 2019

@AndreiCalazans Dude, you're awesome! It totally worked

@react-native-camera react-native-camera locked and limited conversation to collaborators Jan 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests