4

Issue Description

After carefully following the instructions in https://wix.github.io/react-native-navigation/#/docs/Installing, I am getting these errors after completing step 4 for Android:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :react-native-navigation.
Show Details
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :react-native-navigation.
Show Details
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :react-native-navigation.
Show Details
Affected Modules: app

WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getMergeAssets(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app

What I've tried

  • Invalidate Cache/Restart
  • Update dependencies in build.gradle file

    dependencies {
      classpath 'com.android.tools.build:gradle:3.1.4'
      classpath 'com.google.gms:google-services:4.2.0'
    }
    
  • Disable experimental feature for Gradle Only sync the active variant, which leads to two more errors:

    ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :react-native-navigation.
    Show Details
    Affected Modules: app
    
    
    ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :react-native-navigation.
    Show Details
    Affected Modules: app
    
  • Preferences > Appearance & Behavior > System Settings > HTTP Proxy > No Proxy

  • Move google() to the top

    buildscript{
      ext {...}
      repositories {
        google()
        mavenLocal()
        ...
      }
      ...
    }
    allprojects {
      repositories {
        google()
        ...
      }
    }
    
  • Update the gradle distributionUrl to 5.1.1-all and remove task wrapper

  • Remove .gradle, referenced here
    1. Invalidate caches / restart
    2. Shutdown Android Studio
    3. Remove .gradle folder
    4. Restart Android Studio
  • Set proxy both http and https in gradle.properties

    systemProp.http.proxyHost=127.0.0.1
    systemProp.https.proxyPort=12345
    org.gradle.jvmargs=-Xmx1234m
    systemProp.https.proxyHost=127.0.0.1
    systemProp.http.proxyPort=12345
    
  • Open an issue on wix/react-native-navigation
  • Exit Android Studio, delete *.iml file and .idea directory, and rebuild
  • Disable Instant Run

Steps to Reproduce

Step 1

Add the following

# android/settings.gradle

include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/lib/android/app/')

Step 2

Make sure you're using the new gradle plugin

# android/gradle/wrapper/gradle-wrapper.properties

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

Step 3

Update android/build.gradle

# android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 19
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()
        mavenLocal()
        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://jitpack.io' }
    }
}

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

Step 4

Update project dependencies

# android/app/build.gradle

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {...}
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ...
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-navigation')
}

Sync project as necessary confirming that after step 4 the errors are produced

Environment

  • React Native Navigation version: 2.7.0
  • React Native version: 0.57.8
  • Platform(s) (iOS, Android, or both?): Android
  • Android Studio 3.3
  • Gradle 4.10.1
  • Android Gradle plugin 3.3.0
  • Android SDK Build Tools 28.0.3
  • macOS Mojave 10.14.2
  • Java 8 (brew cask)
Joseph K.
  • 1,055
  • 3
  • 23
  • 46

2 Answers2

0

Proceeding to follow step 7 has gotten rid of the error

Step 7

Target the React Native version required by your project by specifying the RNN build flavor in android/app/build.gradle

android {
  defaultConfig {
    missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57_5"
  }
}
Joseph K.
  • 1,055
  • 3
  • 23
  • 46
0

I spent already 2 weeks trying to configure properly the react-native-navigation v2 so feel free to try my app-skeleton: https://github.com/Cicko/react-native-app-skeleton

which is fully set up and ready for development :)

Rudy
  • 158
  • 9
  • I cloned the repo, npm installed, and ran `npm run android` and it builds successfully but it does not run the app in the emulator. am I missing a step? Is it because I'm using Android Studio 3.3? Btw I needed to update Gradle plugin to 3.3.0 and Gradle to 4.10.1 as recommended by Android Studio. This is the same problem I'm having after completing all the installation steps in the RNN docs, I've posted a question here: https://stackoverflow.com/questions/54245925/npm-run-android-does-not-launch-the-android-app – Joseph K. Jan 18 '19 at 18:06
  • Unlike `npm run ios` that opens you the emulator. For android you have to open the emulator first, through Android Studio for example. Then when you run `npm run android` the app should be installed in the emulator. – Rudy Jan 21 '19 at 08:10
  • I found out that when I followed the exact versions mentioned in the installation guide, I was able to run the app without a problem through the emulator by Android Studio. As you have said, the app does get installed in the emulator, and requires to manually launch the app. This was sorted out through the other stackoverflow question that i mentioned. So I think I made a mistake by updating Gradle plugin and Gradle for your repo. – Joseph K. Jan 21 '19 at 08:37