2

I am new to React native trying to start a new project. I followed google docs and already had the android studio installed. added ANROID_HOME to env variables and platform tools to system variables as mentioned in the docs. while running ```react-native run-android``. I get this error

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'AwesomeProject'.

> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.4.2.

my android studio version plugin is 3.4.2 and here is my build.gradle file :

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

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.2")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

and my gradle-wrapper.properties file

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Alireza tk
  • 468
  • 1
  • 7
  • 25

1 Answers1

4

Thanks all for the Answers I think I will provide the answer here for others to use.

my issue was due to the version conflict of gradle and android studi plugin.

1- open android studio and start a new project
2- There should be a builde.gradle and gradle wrapper file
3- the versions you see for gradle here for e.g 5.1.1 or etc is the version you must use in your project**
4- change the classpath com.android.tools.build:gradle:to 3.4.2 in your project build.gradle file

5- change the gradle wrapper properties distribution path to distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

Alireza tk
  • 468
  • 1
  • 7
  • 25