0

I have tried the existing solutions in SO but nothing works.. Any guess where I am wrong. I just updated the gradle in gradle-wrapper.properties

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

and here is my android/build.gradle

wrapper {
    gradleVersion = '5.1.1'
    distributionUrl = distributionUrl.replace("bin", "all")
}

My android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
    googlePlayServicesVersion = "+"
}
buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
        googlePlayServicesVersion = "15.0.1"
        googlePlayServicesAuthVersion = "15.0.1"
        firebaseVersion = "16.0.4"
    }
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        // classpath 'com.android.tools.build:gradle:3.1.2' // <--- use this version or newer
        classpath 'com.google.gms:google-services:4.2.0' // <--- use this version or newer
    }
}

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

subprojects {
  project.configurations.all {
      afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
  }
}

wrapper {
    gradleVersion = '5.1.1'
    distributionUrl = distributionUrl.replace("bin", "all")
}

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-gcm:12.0.1'
   }
}

Android studio gradle file sync

Here I attached through gist since we have character limitation in posting directly.

Gist

Prabhakaran8737
  • 81
  • 3
  • 17

5 Answers5

1

I am not sure, whether I am correct or not.. I just commented these lines

subprojects {
  project.configurations.all {
      afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
  }
}

And works fine...

Prabhakaran8737
  • 81
  • 3
  • 17
0

Move the subprojects section inside allProjects:

allprojects {

{...} //The rest of your config

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
        android {
            compileSdkVersion rootProject.ext.compileSdkVersion
            buildToolsVersion rootProject.ext.buildToolsVersion
        }
    }
    }
}

}

sebastianf182
  • 9,844
  • 3
  • 34
  • 66
0
  1. Move the Entire React Native project in C drive. Open Command Line inside the project.
  2. cd android
  3. ./gradlew clean
  4. cd ..
  5. react-native run-android

The issue may be ur having more than one react native project inside the same project folder.

Hope it will work.

kader hussain
  • 67
  • 1
  • 1
  • 4
0

For RN 0.57 try

classpath 'com.android.tools.build:gradle:3.2.0'

gradleVersion = '4.6'

Check release notes for 0.57 here:

https://github.com/react-native-community/releases/blob/master/CHANGELOG.md

Update:

for RN 0.57.2 I used:

com.android.tools.build:gradle:3.1.4
Android studio 3.1.4
gradle 4.4

for RN 0.58.6 I used:

 classpath 'com.android.tools.build:gradle:3.3.0'
 gradleVersion '4.7'
 Android studio 3.1.4
Florin Dobre
  • 9,872
  • 3
  • 59
  • 93
  • It show the minimum version is 4.6 and changed to 4.6, but still facing the other issue error: resource android:attr/fontVariationSettings not found. `android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:475: error: resource android:attr/fontVariationSettings not found.` and `android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:475: error: resource android:attr/ttcIndex not found` – Prabhakaran8737 Jul 04 '19 at 14:52
  • Tried but the same issue, it shows the minimum required and I used the minimum required version and then the same issue – Prabhakaran8737 Jul 05 '19 at 12:54
  • https://stackoverflow.com/questions/49208772/error-resource-androidattr-fontvariationsettings-not-found Try `compileSdkVersion 28`. You might also have to change targetSdkVersion as '28'. – Florin Dobre Jul 05 '19 at 15:40
  • https://stackoverflow.com/questions/51291407/androidx-modules-androidattr-ttcindex-androidattr-fontvariationsettings-not/51291698 – Florin Dobre Jul 05 '19 at 15:42
  • Tried with the 28 version and now the different issue `Android tasks have already been created. This happens when calling android.applicationVariants, android.libraryVariants or android.testVariants` – Prabhakaran8737 Jul 08 '19 at 04:45
  • You need to update your root gradle (android/gradle) and app gradle files (android/app/gradle). Check how those files look for a newly created project. https://stackoverflow.com/questions/29910720/android-studio-error-building-android-tasks-have-already-been-created – Florin Dobre Jul 08 '19 at 13:56
0
subprojects { project -> 
  afterEvaluate {
        if((project.plugins.hasPlugin('android') || project.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}
Firoz Ahmed
  • 1,929
  • 16
  • 18