这个问题似乎是重复的,但是我试图在我的android项目中添加react native firebase到我的项目,但是当我尝试运行该项目时却遇到了这个著名的错误:
找不到参数的方法Implementation() [com.google.android.gms:play-services-base:16.0.1]类型的对象 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler。
我进行了很多搜索,但是找到的所有解决方案都不适用于我。 这是我的build.gradle: //顶层构建文件,您可以在其中添加所有子项目/模块共有的配置选项。
inventory[addedItems[k]] = inventory(addedItems[k]) + 1
这也是我的package.json:
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.2.0'
classpath 'com.google.gms:google-services:4.2.0'
// This should be here already
implementation project(':react-native-firebase')
// Firebase dependencies
implementation "com.google.android.gms:play-services-base:16.0.1"
implementation "com.google.firebase:firebase-core:16.0.6"
implementation "com.google.firebase:firebase-firestore:17.1.5"
implementation "com.google.firebase:firebase-ads:15.0.1"
implementation "com.google.firebase:firebase-auth:16.1.0"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation "com.google.firebase:firebase-database:16.0.5"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//classpath 'com.google.gms:google-services:3.2.0'
}
apply plugin: 'com.google.gms.google-services'
}
allprojects {
repositories {
mavenLocal()
google() // <-- Add this line above jcenter
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")
}
您能帮我解决问题所在吗?预先感谢
答案 0 :(得分:1)
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.2.0'
除其他事项外;这些需要在您的项目build.gradle
(android / build.gradle)中,而不是应用程序build.gradle
(android / app / build.gradle)中,并且应用程序gradle中的所有implementation
依赖项,而不是您的项目gradle。
有关项目build.gradle
的工作示例,请参见以下内容:
和一个应用程序构建包:
https://github.com/invertase/react-native-firebase/blob/master/tests/android/build.gradle#L9-L11
感谢Salakar @ React Native Firebase