【问题标题】:React Native Image Picker not configures未配置 React Native Image Picker
【发布时间】:2018-12-09 02:35:40
【问题描述】:

我正在尝试将react-native-image-picker 安装到我的 React-native 项目中,我已按照文档的建议进行了配置;如示例所示;我尝试重新安装 Android Studio(3.1 和 3.2);我下载了所有 API 和所有工具;没有什么能解决问题:

Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...

> Configure project :app 
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':react-native-image-picker'.
> Could not resolve all files for configuration ':react-native-image-picker:classpath'.
   > Could not find com.android.tools:common:25.2.3.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/common/25.2.3/common-25.2.3.pom
         https://jcenter.bintray.com/com/android/tools/common/25.2.3/common-25.2.3.jar
     Required by:
         project :react-native-image-picker > com.android.tools.build:gradle:2.2.3 > com.android.tools.build:gradle-core:2.2.3 > com.android.tools.build:builder:2.2.3
         project :react-native-image-picker > com.android.tools.build:gradle:2.2.3 > com.android.tools.build:gradle-core:2.2.3 > com.android.tools.build:builder:2.2.3 > com.android.tools.build:manifest-merger:25.2.3
         project :react-native-image-picker > com.android.tools.build:gradle:2.2.3 > com.android.tools.build:gradle-core:2.2.3 > com.android.tools.build:builder:2.2.3 > com.android.tools.ddms:ddmlib:25.2.3
         project :react-native-image-picker > com.android.tools.build:gradle:2.2.3 > com.android.tools.build:gradle-core:2.2.3 > com.android.tools.build:builder:2.2.3 > com.android.tools.analytics-library:shared:25.2.3
         project :react-native-image-picker > com.android.tools.build:gradle:2.2.3 > com.android.tools.build:gradle-core:2.2.3 > com.android.tools.build:builder:2.2.3 > com.android.tools.analytics-library:tracker:25.2.3
         project :react-native-image-picker > com.android.tools.build:gradle:2.2.3 > com.android.tools.build:gradle-core:2.2.3 > com.android.tools.build:builder:2.2.3 > com.android.tools:sdklib:25.2.3 > com.android.tools.layoutlib:layoutlib-api:25.2.3
         project :react-native-image-picker > com.android.tools.build:gradle:2.2.3 > com.android.tools.build:gradle-core:2.2.3 > com.android.tools.build:builder:2.2.3 > com.android.tools:sdklib:25.2.3 > com.android.tools:dvlib:25.2.3
         project :react-native-image-picker > com.android.tools.build:gradle:2.2.3 > com.android.tools.build:gradle-core:2.2.3 > com.android.tools.build:builder:2.2.3 > com.android.tools:sdklib:25.2.3 > com.android.tools:repository:25.2.3

* 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 1m 9s
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

我的 package.json:

{
  "name": "MyTestApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "moment": "^2.22.2",
    "react": "16.6.1",
    "react-native": "0.57.5",
    "react-native-datepicker": "^1.7.2",
    "react-native-image-picker": "^0.27.1",
    "react-native-loading-spinner-overlay": "^1.0.1",
    "react-native-picker-select": "^5.1.0",
    "react-navigation": "^2.18.2"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.49.2",
    "react-test-renderer": "16.6.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

有什么问题吗?

更新

我的 build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

        // 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.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

【问题讨论】:

  • 您能提供您的android/build.gradleandroid/app/build.gradle 文件吗?
  • 刚刚更新@AnonymousSB
  • 好的,我怀疑我知道这个问题,我会在下面提供答案。
  • Hello All 更新您的所有节点模块包,其中出现“react-native-image-picker”之类的错误在 android studio 中打开这个 android 项目并在个人中更新 gradle。

标签: react-native react-native-image-picker


【解决方案1】:

Android 包有自己的构建工具依赖项,这可能会导致这样的错误。最好的解决方案是修改您的 android/build.gradleandroid/app/build.gradle 以覆盖子项目以使用与您的应用使用的构建工具相同的构建工具。

android/build.gradle

ext {
    compileSdkVersion = 26
    buildToolsVersion = "26.0.1"
}
buildscript {
    ... Keep this the same ...
}
subprojects { subproject ->
    afterEvaluate{
        if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}

android/app/build.gradle

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    ... whatever else you have here ...
}

【讨论】:

  • 太棒了!非常感谢!我花了三天时间寻找它!
【解决方案2】:

升级到最新版本的react-native-image-picker(撰写本文时为0.27.2)似乎可以解决这个问题。

【讨论】:

    【解决方案3】:
    Update your all node module package which getting error like "react-native-image-picker" 
    open this android project in android studio and update
    gradle in individual-individual
    
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
    

    它会帮助你。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2021-06-29
      • 2021-10-20
      • 2020-03-02
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多