“Could not get unknown property 'mergeResourcesProvider' for object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.”

99封情书 提交于 2020-01-01 08:05:03

问题


{
  "name": "RNNProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.8.3",
    "react-native": "0.59.1",
    "react-native-navigation": "^2.15.0"
  },
  "devDependencies": {
    "@babel/core": "7.4.0",
    "@babel/runtime": "7.4.2",
    "babel-jest": "24.5.0",
    "jest": "24.5.0",
    "metro-react-native-babel-preset": "0.53.1",
    "react-test-renderer": "16.8.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

graddle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

Build Graddle
 dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1' }

回答1:


I resolved this issue by doing the following steps:

  1. in android/gradle/wrapper/gradle-wrapper.properties change distributionUrl value to distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip.
  2. in android/build.gradle change classpath to 'com.android.tools.build:gradle:3.3.0'.
  3. *Optional (if using Metro) create metro.config.js in your project directory and put this code into it .
  4. *Optional (if using Metro) And make sure version of metro in package.json "metro-react-native-babel-preset": "0.51.0" is right in your packge.json file.
  5. remove node_modules folder and run yarn install.



回答2:


This happens when you have react native version updated but your project code is not compatible with react native version.

So you need to do changes manually. You can do it by using react-native upgrade helper

https://react-native-community.github.io/upgrade-helper

Specify your current react-native version and the version would you like to update. You can see the changes that need to be done

Attaching screenshot for help




回答3:


Resolved my issue by following these steps

  1. Remove node_modules and package-lock.json/yarn.lock.
  2. Set distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip in gradle-wrapper.properties
  3. Add classpath(com.android.tools.build:gradle:3.4.0) in android/build.gradle under buildscript.dependencies.
  4. Run yarn.

You may run into other errors due to gradle upgrade which needs to be resolved.




回答4:


Extra to Omar Al-Howeiti's answer.

Add android:usesCleartextTraffic="true" to AndroidManifest.xml

  <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:usesCleartextTraffic="true"
      android:theme="@style/AppTheme">


来源:https://stackoverflow.com/questions/55299138/could-not-get-unknown-property-mergeresourcesprovider-for-object-of-type-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!