javascript - React Native Android 构建, "ERROR: Could not get unknown property ' mergeResourcesProvider'"

标签 javascript react-native gradle android-gradle-plugin

我已经使用 RN 0.59.3 升级了我的应用程序,自从我在构建 Android 时收到错误消息。 iOS 可以很好地构建应用程序。

安卓工作室

错误:无法为类型为 com.android.build.gradle.internal.api.ApplicationVariantImpl 的对象获取未知属性“mergeResourcesProvider”。

控制台

error 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
error Command failed: ./gradlew app:installSabdebugDebug

我尝试将 android/app/gralde/wrapper/gradle-wrapper.propeties 中的 distributionUrl 更改为

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

并且我将 build.gradle 依赖项升级到这些版本

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
    classpath 'com.google.gms:google-services:4.2.0'
    ...
}

这是整个文档

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

buildscript {
    ext {
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        androidMapsUtilsVersion = "0.5+"
        googlePlayServicesAuthVersion = "16.0.1"
    }

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.2.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

我正在设置这些 app/build.gradle

android {
      compileSdkVersion safeExtGet('compileSdkVersion', 28)
    buildToolsVersion safeExtGet('buildToolsVersion', '28.0.0')

    defaultConfig {
        applicationId "com.myapp"
        resValue "string", "build_config_package", "com.myapp"
        minSdkVersion 18
        multiDexEnabled true
        targetSdkVersion 26
        versionCode 24
        versionName "1.3.5"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
...

我的 package.json

"dependencies": {
    "babel-plugin-transform-remove-console": "^6.9.4",
    "formik": "^1.3.1",
    "lodash": "^4.17.10",
    "moment": "^2.23.0",
    "moment-timezone": "^0.5.21",
    "native-base": "^2.8.1",
    "react": "16.8.3",
    "react-native": "0.59.3",
    ....
}
"devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/runtime": "^7.4.3",
    "babel-jest": "^24.7.0",
    "jest": "^24.7.0",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-test-renderer": "16.8.3",
    "run-script-os": "~1.0.5"
  },

我们还使用脚本通过 run-script-os 构建应用程序的不同环境,但我不认为这是导致问题的原因。

我也有找不到 Android sdk 的错误,但我用 local.properties 解决了这个问题。

干杯!

最佳答案

gradle-wrapper.properties: 中更改 distributionUrl

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

然后在根 build.gradle 文件中将 gradle classpath 更改为:

类路径 'com.android.tools.build:gradle:3.3.0'

删除 node_modulesnpm install && react-native run-android 再次。

关于javascript - React Native Android 构建, "ERROR: Could not get unknown property ' mergeResourcesProvider'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55493997/

相关文章:

javascript - 处理旅行动画

启用兼容模式的 IE 8 中的 Javascript 错误

javascript - execCommand ('insertHTML' ) 正在占用空间

android - Android Studio添加gradle存储库给出 “Invalid variable name. Must start with a letter”

gradle - 通过 'org.gradle.java.home' 提供的 Java 主页无效。无效目录 :/usr/local/java/jdk1. 8.0_05

javascript - 如何在plupload中定义过滤器

javascript - 当 ListView 放置在 ScrollView 中时,ListView 的 onEndReached 属性不起作用

javascript - 如何让 React Native 的 ScrollView 初始缩放不为 1?

react-native - react native Flex 高度

gradle - Gradle 5.0:java.lang.String无法转换为类groovy.lang.Closure(Lombok问题)