4

I followed the intructions of React Native Getting Started, in the "Building Projects with Native Code" tab, for Windows and Android.

This is the content of the \AwesomeProject\android\build.gradle and after this there is the error I get when I execute: react-native run-android

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

buildscript {
    ext {
        buildToolsVersion = "28.0.2"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

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

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"
        }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}

When I execute: react-native run-android, I get the following error output:

D:\studio\study\reactnatv\AwesomeProject>react-native run-android
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...

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.0.1.
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
     Required by:
         project :

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Command failed: gradlew.bat installDebug

Error: Command failed: gradlew.bat installDebug
    at checkExecSyncError (child_process.js:616:11)
    at Object.execFileSync (child_process.js:634:13)
    at runOnAllDevices (D:\studio\study\reactnatv\AwesomeProject\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
    at buildAndRun (D:\studio\study\reactnatv\AwesomeProject\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
    at isPackagerRunning.then.result (D:\studio\study\reactnatv\AwesomeProject\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
    at process._tickCallback (internal/process/next_tick.js:68:7)


D:\studio\study\reactnatv\AwesomeProject>

I checked this US sanctions solution but it did not worked.

What am I doing wrong ?

Elio Lako
  • 1,333
  • 2
  • 16
  • 26
eliastg
  • 449
  • 1
  • 4
  • 14

4 Answers4

6

You have to change this line at your project :

dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
}
Elio Lako
  • 1,333
  • 2
  • 16
  • 26
  • 1
    Thank you for answer. I made the change you sugested, but I got a similar error: * What went wrong: A problem occurred configuring root project 'AwesomeProject'. > Could not resolve all artifacts for configuration ':classpath'. > Could not resolve com.android.tools.build:gradle:3.0.1. Required by: project : > Could not resolve com.android.tools.build:gradle:3.0.1. > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'. – eliastg Mar 27 '19 at 15:03
  • @eliastg you have to change the version as i stated, at your "build.gradle" file. Did you managed to do it? – Elio Lako Mar 28 '19 at 10:38
4

The problem was caused by my location. I had to use a tunnel for this. In that moment I created an SSH account here https://www.dynamicssh.com/create-ssh

  1. With SSH credentials it is possible to set a local tunnel. I use Linux, so the tunnel can be set with this command.

    $ ssh -D 1337 -q -C -N youruser@yourserver.something

More details about it here: https://ma.ttias.be/socks-proxy-linux-ssh-bypass-content-filters/

In Windows, I think it is possible to use a tool called Bitvise SSH.

  1. Defined the variables https_proxy and http_proxy on the terminal for localhost:1337 (The port is the one you use to set the tunnel in the previous step.) This is to use the tunnel in the terminal.

  2. Then run the "react-native run-android", in the same terminal where https_proxy and http_proxy were set.

Thank to all who answered.

Best regards.

eliastg
  • 449
  • 1
  • 4
  • 14
  • 1
    Yeah, `dl.google.com` is blocked for some countries! – Amir Fo Jun 05 '20 at 15:56
  • 1
    I am using VPN and I keep getting the error. Any specific proxi? – Josué CB Mar 25 '21 at 20:33
  • In that moment I think I used an account from here: https://www.dynamicssh.com/create-ssh Then I used those credentials to create a local port forwarding with a command similar to this: ssh -v -N -D localhost:1090 theuser@ssh-ipdyna-wathever.com With this you can setup http_proxy and https_proxy in the terminal. I hope this helps. – eliastg Mar 28 '21 at 02:15
  • Can you please explain it. I am getting the same error for all my existing projects after I change their directory. – Ishaq Kamran Nov 09 '21 at 18:13
  • @IshaqKamran I have added more details of the solution. I hope it can help you. – eliastg Nov 09 '21 at 19:20
2

Try deleting all of your node_modules folders in the project and then rebuild.

I had this issue, and every time I would try to specify the gradle version it was requiring in my dependencies, I would get a separate error telling me that my gradle version was too low. This was due to some android libraries in node_modules requiring different gradle versions. Rebuilding node_modules from scratch should sync them up.

Joe
  • 31
  • 1
1

Happened to me when my internet was turned off. Worth checking once.

rule_it_subir
  • 650
  • 10
  • 12