【问题标题】:React Native Navigation Error building Android,:app@debug/compileClasspath': Could not resolve project :react-native-navigationReact Native Navigation 构建 Android 时出错,:app@debug/compileClasspath':无法解析项目:react-native-navigation
【发布时间】:2018-08-28 03:02:12
【问题描述】:

我正在尝试安装 react-native-navigation(wix) 包,我正在按照 android(https://wix.github.io/react-native-navigation/#/installation-android) 上的步骤操作,但在 android studio 中,构建失败并显示消息。 Gradle 4.1(我不知道这是否相关)

Could not resolve project :react-native-navigation.
Required by:
project :app

Unable to find a matching configuration of project :react-native-navigation: None of the consumable configurations have attributes.

Error:Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :react-native-navigation.
Open File
Show Details

Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :react-native-navigation.
Open File
Show Details

Error:Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :react-native-navigation.
Open File
Show Details

Error:Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :react-native-navigation.
Open File
Show Details

Error:Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :react-native-navigation.

我在下面留下详细信息(我的用户叫 home,不是错字):

问题描述 local.properties 文件

sdk.dir=/home/home/Android/Sdk

settings.gradle

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

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "com.example.home.myapplication"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.android.support:appcompat-v7:25.0.1"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
   //tried implementation as well here instead of compile but didn't work either 
   compile project(':react-native-navigation')

}

环境

  • React Native Navigation 版本:“1.1.370”
  • React Native 版本:“0.52.0”
  • 平台(iOS、Android 或两者?):Android
  • 设备信息(模拟器/设备?操作系统版本?调试/发布?):Android Studio

我应该在 react native 中使用哪个版本的 gradle 和 android api?有没有办法解决这个问题?我看到我的应用程序 gradle 文件与说明完全不同,编译项目语句在我的 gradle 版本中无效。任何想法?也许 local.settings 是错误的并且没有找到文件?...任何帮助将不胜感激

【问题讨论】:

    标签: android react-native react-native-android react-native-navigation


    【解决方案1】:

    问题是我怀疑的最后一个 gradle 版本与该软件包不兼容。最后我不得不使用 gradle 3 并且一切正常

    【讨论】:

    • 嗨,我面临同样的问题。你能更具体地说明你是如何解决这个问题的吗?
    【解决方案2】:

    环境

    React Native Navigation version: "2.0.2502"
    React Native version: "0.56.0"
    Platform(s) (iOS, Android, or both?): Android
    Device info (Simulator/Device? OS version? Debug/Release?): Android Studio
    

    我关注了official documentation,然后遇到了同样的问题。在我的情况下,我在我的 react-native 项目的 node_modules 中移动了“RNN”文件夹,然后 Gradle 工作了。

    【讨论】:

      【解决方案3】:
      We also get the same problem on my android app, Here is the solution.
       Follow the steps to overcome this error.
      
           Step 1:
      
          Requirements
          node >= 8
          react-native >= 0.51
      
          Step 2:
          npm install --save react-native-navigation
      
          Step 3:
          Add the following in 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 4: 
          Make sure you're using the new gradle plugin, edit android/gradle/wrapper/gradle-wrapper.properties
      
          distributionBase=GRADLE_USER_HOME
          distributionPath=wrapper/dists
          zipStoreBase=GRADLE_USER_HOME
          zipStorePath=wrapper/dists
          +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
          -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
      
          Step 5:
          Update android/build.gradle:
      
          buildscript {
              repositories {
          +        google()
          +        mavenLocal()
          +        mavenCentral()
          +        jcenter()
          -        maven {
          -            url 'https://maven.google.com/'
          -            name 'Google'
          -        }
              }
              dependencies {
          +        classpath 'com.android.tools.build:gradle:3.0.1'
          -        classpath 'com.android.tools.build:gradle:2.2.3'
              }
          }
      
          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://maven.google.com/'
          -            name 'Google'
          -        }
          +        maven { url 'https://jitpack.io' }
              }
          }
      
          ext {
          -    buildToolsVersion = "26.0.3"
          +    buildToolsVersion = "27.0.3"
          -    minSdkVersion = 16
          +    minSdkVersion = 19
              compileSdkVersion = 26
              targetSdkVersion = 26
              supportLibVersion = "26.1.0"
          }
      
          Step 6:
          Update project dependencies in android/app/build.gradle.
          android {
              compileSdkVersion rootProject.ext.compileSdkVersion
              buildToolsVersion rootProject.ext.buildToolsVersion
      
              defaultConfig {
                  applicationId "com.yourproject"
                  minSdkVersion rootProject.ext.minSdkVersion
                  targetSdkVersion rootProject.ext.targetSdkVersion
                  versionCode 1
                  versionName "1.0"
                  ndk {
                      abiFilters "armeabi-v7a", "x86"
                  }
              }
          +    compileOptions {
          +        sourceCompatibility JavaVersion.VERSION_1_8
          +        targetCompatibility JavaVersion.VERSION_1_8
          +    }
              ...
          }
      
          dependencies {
          -    compile fileTree(dir: "libs", include: ["*.jar"])
          -    compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
          -    compile "com.facebook.react:react-native:+"  // From node_modules
          +    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')
          }
      
          Step 7: 
          Update MainActivity.java
          MainActivity.java should extend com.reactnativenavigation.NavigationActivity instead of ReactActivity.
          This file is located in android/app/src/main/java/com/<yourproject>/MainActivity.java.
          -import com.facebook.react.ReactActivity;
          +import com.reactnativenavigation.NavigationActivity;
      
          -public class MainActivity extends ReactActivity { 
          +public class MainActivity extends NavigationActivity {
          -    @Override
          -    protected String getMainComponentName() {
          -        return "yourproject";
          -    }
          }
      
          Step 7:
          Update MainApplication.java
          This file is located in android/app/src/main/java/com/<yourproject>/MainApplication.java.
          ...
          import android.app.Application;
      
          import com.facebook.react.ReactApplication;
          import com.facebook.react.ReactNativeHost;
          import com.facebook.react.ReactPackage;
          import com.facebook.react.shell.MainReactPackage;
          import com.facebook.soloader.SoLoader;
      
          +import com.reactnativenavigation.NavigationApplication;
          +import com.reactnativenavigation.react.NavigationReactNativeHost;
          +import com.reactnativenavigation.react.ReactGateway;
      
          import java.util.Arrays;
          import java.util.List;
      
          -public class MainApplication extends Application implements ReactApplication {
          +public class MainApplication extends NavigationApplication {
          +    
          +    @Override
          +    protected ReactGateway createReactGateway() {
          +        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
          +            @Override
          +            protected String getJSMainModuleName() {
          +                return "index";
          +            }
          +        };
          +        return new ReactGateway(this, isDebug(), host);
          +    }
          +
          +    @Override
          +    public boolean isDebug() {
          +        return BuildConfig.DEBUG;
          +    }
          +
          +    protected List<ReactPackage> getPackages() {
          +        // Add additional packages you require here
          +        // No need to add RnnPackage and MainReactPackage
          +        return Arrays.<ReactPackage>asList(
          +            // eg. new VectorIconsPackage()
          +        );
          +    }
          +  
          +    @Override
          +    public List<ReactPackage> createAdditionalReactPackages() {
          +        return getPackages();
          +    }
          - ...
          +}
      
          Step 8: 
          RNN and React Native version
      
          react-native-navigation supports multiple React Native versions. Target the React Native version required by your project by specifying the RNN build flavor in android/app/build.gradle.
      
          android {
              ...
              defaultConfig {
                  applicationId "com.yourproject"
                  minSdkVersion rootProject.ext.minSdkVersion
                  targetSdkVersion rootProject.ext.targetSdkVersion
          +        missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57" // See note below!
                  versionCode 1
                  versionName "1.0"
                  ...
              }
              ...
          }
      

      更多详情,您可以点击此链接 enter link description here

      【讨论】:

        【解决方案4】:

        您是否安装了 Android SDK 27?在 Android Studio 中打开您的 Android SDK 管理器,并确保在那里安装该版本。还可以尝试创建基于该版本的模拟器。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-04-07
          • 1970-01-01
          • 2022-10-24
          • 2020-07-13
          • 2020-05-19
          • 2019-06-11
          相关资源
          最近更新 更多