在我的应用程序中,我正在尝试使用gcm服务,但我甚至无法编译gradle。我不断收到消息,说我不知道' firebase core'虽然我不知道如何安装它。
这是我的顶级gradle文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath "io.realm:realm-gradle-plugin:1.1.0"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
maven {
url "https://mint.splunk.com/gradle/"
}
}
}
这是我的模块级gradle文件:
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "roof.android"
minSdkVersion 17
targetSdkVersion 23
versionCode 11
versionName "0.0.4"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTIC E.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties'
exclude 'META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.xml'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// "The Android Support Library package contains several libraries that can be included in your application" -- https://developer.android.com/topic/libraries/support-library/features.html
compile 'com.android.support:appcompat-v7:24.0.0'
// "Native android recycler view library" -- https://developer.android.com/topic/libraries/support-library/features.html
compile 'com.android.support:recyclerview-v7:24.0.0'
// "A powerful image downloading and caching library for Android" -- http://square.github.io/picasso/
compile 'com.squareup.picasso:picasso:2.5.2'
// "Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster" -- https://developer.android.com/training/volley/index.html
compile 'com.android.volley:volley:1.0.0'
// "JsonWebTokens in Auth0" -- https://auth0.com/docs/jwt
compile 'com.auth0:java-jwt:2.1.0'
// "Joda-Time provides a quality replacement for the Java date and time classes" -- http://www.joda.org/joda-time/
compile 'joda-time:joda-time:2.8.1'
// "Android loading or progress dialog widget library, provide efficient way to implement iOS like loading dialog and progress wheel" -- https://github.com/Cloudist/ACProgressLite
compile 'cc.cloudist.acplibrary:library:1.2.1'
// "A RecyclerView that is powered by Realm and lots more" -- https://github.com/thorbenprimke/realm-recyclerview
compile 'com.github.thorbenprimke:realm-recyclerview:0.9.22'
// "A beautiful ripple animation for your app" -- https://github.com/skyfishjy/android-ripple-background
compile 'com.skyfishjy.ripplebackground:library:1.0.1'
// "A logger with a small, extensible API which provides utility on top of Android's normal Log class." -- http://jakewharton.github.io/timber/
compile 'com.jakewharton.timber:timber:4.1.2'
// "Field and method binding for Android views" -- http://jakewharton.github.io/butterknife/
compile 'com.jakewharton:butterknife:8.1.0'
apt 'com.jakewharton:butterknife-compiler:8.1.0'
// "An HTTP+HTTP/2 client for Android and Java applications." -- http://square.github.io/okhttp/
compile 'com.squareup.okhttp3:okhttp:3.3.1'
// "Android client for Sentry"
compile 'com.joshdholtz.sentry:sentry-android:1.4.1'
compile 'com.google.android.gms:play-services-gcm:9.2.0'
}
答案 0 :(得分:14)
在您的模块Gradle文件(通常是app/build.gradle
)中,在文件底部添加apply plugin(apply plugin: 'com.google.gms.google-services'
)行以启用Gradle插件。
您还应该为Firebase com.google.firebase:firebase-core
和com.google.firebase:firebase-messaging
SDK添加依赖项:
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
确保在使用 Firebase 时安装了最新版本的'Google Play服务'和'Google Repository'。
请按照以下步骤安装:
最后,再次同步和构建您的项目。
答案 1 :(得分:4)
您想在自己的应用中添加推送通知吗?
使用firebase而不是GCM。它是GCM的增强版。
您需要以下依赖于firebase推送通知。
compile 'com.google.firebase:firebase-messaging:9.0.1'
compile 'com.google.android.gms:play-services-gcm:9.0.1'
有关详细信息,请访问http://codingaffairs.blogspot.com/2016/06/firebase-cloud-messaging-push.html
答案 2 :(得分:2)
如果要添加firebase核心,可以添加
compile 'com.google.firebase:firebase-core:9.0.0'
在模块级gradle文件中的依赖项标记下。
如果您仍无法解决问题,可能需要先更新SDK才能获得Google Play服务第30版和Google Repository第26版。有关详细信息,请参阅here。
答案 3 :(得分:2)
我在com.google.firebase:firebase-core:11.8.0
上遇到了同样的问题,将google()
存储库移到jcenter()
上方后,它仍然起作用。
我之间使用的是Build -> Clean Project
。
./ build.gradle
buildscript {
repositories {
google() // <- now on top!
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
google() // <- now on top!
jcenter()
}
}
答案 4 :(得分:0)
在存储区部分的android / build.gradle中,尝试将 google()移到 jcenter()上。