我已经尝试了SO中的现有解决方案,但无济于事。我猜错了。我刚刚在gradle-wrapper.properties中更新了gradle
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
这是我的android / build.gradle
wrapper {
gradleVersion = '5.1.1'
distributionUrl = distributionUrl.replace("bin", "all")
}
我的 android / build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
googlePlayServicesVersion = "+"
}
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
googlePlayServicesVersion = "15.0.1"
googlePlayServicesAuthVersion = "15.0.1"
firebaseVersion = "16.0.4"
}
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// classpath 'com.android.tools.build:gradle:3.1.2' // <--- use this version or newer
classpath 'com.google.gms:google-services:4.2.0' // <--- use this version or newer
}
}
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"
}
maven { url 'https://maven.google.com' }
maven { url "https://jitpack.io" }
}
}
subprojects {
project.configurations.all {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
}
wrapper {
gradleVersion = '5.1.1'
distributionUrl = distributionUrl.replace("bin", "all")
}
configurations.all {
resolutionStrategy {
force 'com.google.android.gms:play-services-gcm:12.0.1'
}
}
Android studio gradle文件同步
由于我们在直接发布内容方面存在字符限制,因此我通过要点进行了附加。
答案 0 :(得分:1)
我不确定我是否正确。我只是在评论这些行
subprojects {
project.configurations.all {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
}
工作正常...
答案 1 :(得分:0)
在allProjects中移动子项目部分:
allprojects {
{...} //The rest of your config
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
}
答案 2 :(得分:0)
问题可能是您在同一项目文件夹中具有多个React Native项目。
希望它会起作用。
答案 3 :(得分:0)
对于RN 0.57,请尝试
classpath 'com.android.tools.build:gradle:3.2.0'
gradleVersion = '4.6'
在此处查看0.57的发行说明:
https://github.com/react-native-community/releases/blob/master/CHANGELOG.md
更新:
对于我使用的RN 0.57.2:
com.android.tools.build:gradle:3.1.4
Android studio 3.1.4
gradle 4.4
对于我使用的RN 0.58.6:
classpath 'com.android.tools.build:gradle:3.3.0'
gradleVersion '4.7'
Android studio 3.1.4
答案 4 :(得分:0)
subprojects { project ->
afterEvaluate {
if((project.plugins.hasPlugin('android') || project.plugins.hasPlugin('android-library'))) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}