React Native Android构建,“错误:无法获取未知属性'mergeResourcesProvider'”

时间:2019-04-03 11:24:08

标签: javascript react-native gradle android-gradle

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

Android Studio

错误:无法获取类型为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.properties中的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解决了该问题。

干杯!

2 个答案:

答案 0 :(得分:1)

*在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_modules并再次运行android。

答案 1 :(得分:0)

修改:工作版本

我已使用

升级了我的应用
[Ljava.lang.String;@548c4f57

android / app / gradle / wrapper / gradle-wrapper.properties

   "react": "16.8.6",
   "react-native": "0.59.8"

android / build.gradle

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

这是整个文档

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

android / app / build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 19
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        appCompatVersion = "28.0.0"
        androidMapsUtilsVersion = "0.5+"

        googlePlayServicesAuthVersion = "16.0.1"
        googlePlayServicesBaseVersion = "16.1.0"
        googlePlayServicesLocationVersion = "16.0.0"
        googlePlayServicesPlacesVersion = "1.1.0"
        firebaseCoreVersion = "16.0.9"
        firebaseMessagingVersion = "18.0.0"
    }

    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"
        }
        // maven {
        //     // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        //     url "https://maven.google.com"
        // }
    }
}

我的 package.json

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

    defaultConfig {
        applicationId "com.sportjoe"
        resValue "string", "build_config_package", "com.myapp"
        minSdkVersion safeExtGet('minSdkVersion', 19)
        multiDexEnabled true
        targetSdkVersion safeExtGet( 'targetSdkVersion' , 28 )
        versionCode 34
        versionName "1.4.11"
        ndk {
            abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
        }
    }
...

现在似乎为我工作,希望对您有所帮助!