【问题标题】:Unable to resolve dependency for '...': Could not resolve project :react-native-navigation无法解析“...”的依赖关系:无法解析项目:react-native-navigation
【发布时间】:2019-06-11 09:28:58
【问题描述】:

问题描述

仔细按照https://wix.github.io/react-native-navigation/#/docs/Installing 中的说明进行操作后,我在完成 Android 的第 4 步后收到这些错误:

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

我尝试过的

  • 使缓存无效/重新启动
  • 更新build.gradle file中的依赖项

    dependencies {
      classpath 'com.android.tools.build:gradle:3.1.4'
      classpath 'com.google.gms:google-services:4.2.0'
    }
    
  • 禁用 Gradle Only sync the active variant 的实验功能,这会导致另外两个错误:

    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
    
  • 首选项 > 外观和行为 > 系统设置 > HTTP 代理 > 无代理

  • google() 移至顶部

    buildscript{
      ext {...}
      repositories {
        google()
        mavenLocal()
        ...
      }
      ...
    }
    allprojects {
      repositories {
        google()
        ...
      }
    }
    
  • 将 gradle distributionUrl 更新为 5.1.1-all 并移除任务包装器

  • 删除.gradle,引用here
    1. 使缓存无效/重新启动
    2. 关闭 Android Studio
    3. 删除 .gradle 文件夹
    4. 重启 Android Studio
  • 在 gradle.properties 中设置 http 和 https 的代理

    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
    
  • 在 wix/react-native-navigation 上打开 issue
  • 退出Android Studio,删除*.iml文件和.idea目录,重新构建
  • 禁用即时运行

复制步骤

步骤 1

添加以下内容

# android/settings.gradle

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

第二步

确保您使用的是新的 gradle 插件

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

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

第三步

更新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")
}

第四步

更新项目依赖

# 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')
}

根据需要同步项目,确认在第 4 步之后产生了错误

环境

  • React Native Navigation 版本:2.7.0
  • React Native 版本:0.57.8
  • 平台(iOS、Android 或两者?):Android
  • Android Studio 3.3
  • Gradle 4.10.1
  • Android Gradle 插件 3.3.0
  • Android SDK 构建工具 28.0.3
  • macOS Mojave 10.14.2
  • Java 8(酿造桶)

【问题讨论】:

    标签: android-studio react-native gradle synchronization react-native-navigation


    【解决方案1】:

    继续执行步骤 7 已消除错误

    第 7 步

    通过在 android/app/build.gradle 中指定 RNN 构建风格来定位项目所需的 React Native 版本

    android {
      defaultConfig {
        missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57_5"
      }
    }
    

    【讨论】:

      【解决方案2】:

      我已经花了 2 周时间尝试正确配置 react-native-navigation v2,所以请随意尝试我的 app-skeleton:https://github.com/Cicko/react-native-app-skeleton

      已完全设置好并准备好开发:)

      【讨论】:

      • 我克隆了repo,安装了npm,运行npm run android,它构建成功,但它没有在模拟器中运行应用程序。我错过了一步吗?是因为我使用的是 Android Studio 3.3 吗?顺便说一句,我需要按照 Android Studio 的建议将 Gradle 插件更新到 3.3.0 和 Gradle 到 4.10.1。这与我在完成 RNN 文档中的所有安装步骤后遇到的问题相同,我在这里发布了一个问题:stackoverflow.com/questions/54245925/…
      • 不像npm run ios 那样打开模拟器。对于 android,您必须首先打开模拟器,例如通过 Android Studio。然后当你运行npm run android 时,应用程序应该安装在模拟器中。
      • 我发现当我按照安装指南中提到的确切版本进行操作时,我能够通过 Android Studio 的模拟器毫无问题地运行该应用程序。正如您所说,该应用程序确实安装在模拟器中,并且需要手动启动该应用程序。这是通过我提到的另一个 stackoverflow 问题解决的。所以我认为我为你的 repo 更新 Gradle 插件和 Gradle 是一个错误。
      猜你喜欢
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 2021-06-15
      • 1970-01-01
      • 2018-06-26
      • 2020-09-09
      • 2022-01-23
      • 1970-01-01
      相关资源
      最近更新 更多