Java 如何在android应用程序中添加firebase依赖项?
我想将firebase添加到我的项目中,这是我的依赖项:Java 如何在android应用程序中添加firebase依赖项?,java,android,firebase,android-studio,Java,Android,Firebase,Android Studio,我想将firebase添加到我的项目中,这是我的依赖项: implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.2.0' implementatio
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.3.3'
implementation 'androidx.navigation:navigation-ui:2.3.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.3'
implementation 'com.android.support:multidex:1.0.3'
implementation 'io.reactivex.rxjava2:rxjava:2.2.11'
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
//Retrofit
implementation "com.squareup.retrofit2:retrofit:${retrofit_version}"
implementation "com.squareup.retrofit2:converter-gson:${retrofit_version}"
implementation "com.squareup.retrofit2:adapter-rxjava2:${retrofit_version}"
//http interceptor
implementation "com.squareup.okhttp3:okhttp:${interceptor_version}"
implementation "com.squareup.okhttp3:logging-interceptor:${interceptor_version}"
// Material Dialog Library
implementation 'com.shreyaspatil:MaterialDialog:2.1'
// Material Design Library
implementation 'com.google.android.material:material:1.3.0'
// Lottie Animation Library
implementation 'com.airbnb.android:lottie:3.4.0'
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0"
// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:2.3.0"
implementation "androidx.room:room-runtime:2.2.6"
kapt "androidx.room:room-compiler:2.2.6"
// For Kotlin use kapt instead of annotationProcessor
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:2.2.6"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
//dagger
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
//http interceptor
implementation "com.squareup.okhttp3:okhttp:${interceptor_version}"
implementation "com.squareup.okhttp3:logging-interceptor:${interceptor_version}"
//Glide
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
implementation 'com.google.android.material:material:1.3.0'
//Kodein Dependency Injection
implementation "org.kodein.di:kodein-di-generic-jvm:6.2.1"
implementation "org.kodein.di:kodein-di-framework-android-x:6.2.1"
implementation 'com.github.dhaval2404:imagepicker:1.7.5'
implementation 'com.github.gcacace:signature-pad:1.2.1'
// implementation 'com.google.android.gms:play-services:17.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.airbnb.android:lottie:3.4.0'
implementation 'com.github.mayuce:LottieAlertDialog:1.1'
implementation 'com.applandeo:material-calendar-view:1.7.0'
implementation 'com.applandeo:material-calendar-view:1.9.0-alpha03'
implementation 'com.applandeo:material-calendar-view:1.9.0-alpha03'
//Rx java
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.11'
//dexter
implementation 'com.karumi:dexter:6.2.2'
//Location
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.hbb20:ccp:2.4.0'
implementation 'com.github.prabhat1707:EasyWayLocation:2.0'
//Aws
implementation 'com.amazonaws:aws-android-sdk-s3:2.18.0'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.18.0'
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.18.0'
implementation 'com.github.mukeshsolanki:Google-Places-AutoComplete-EditText:0.0.8'
// implementation project(':maplibrary')
implementation 'com.google.android.libraries.places:places:2.4.0'
implementation 'org.jetbrains.anko:anko-support-v4-commons:0.10.8'
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.bitvale:lightprogress:1.0.1'
implementation 'com.github.timigod:android-chat-ui:v0.1.4'
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
implementation 'com.facebook.shimmer:shimmer:0.1.0@aar'
implementation 'com.github.bassaer:chatmessageview:2.0.1'
implementation 'com.google.android.gms:play-services-analytics:17.0.0'
// implementation 'com.google.firebase:firebase-messaging:21.0.1'
implementation platform('com.google.firebase:firebase-bom:26.5.0')
// Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-analytics'
但是,当我想添加firebase时,出现了以下错误:
Failed to resolve: com.google.android.gms:play-services-measurement-sdk:12.0.1
Show in Project Structure dialog
Affected Modules: app
此外,我还在应用程序级别和build.gradle项目级别的build.gradle
底部添加了apply插件:“com.google.gms.google服务”:
//顶级生成文件,您可以在其中添加所有子项目/模块通用的配置选项
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'
classpath 'com.google.gms:google-services:4.3.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://maven.google.com" }
maven { url "https://www.jitpack.io" }
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex')) {
details.useVersion "12.0.1"
}
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我修复了我的问题,将所有包更新为最新版本,并从应用程序级别和项目级别的build.gradle文件中删除了一些代码,如下所示:在项目级别build.gradle中:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.2"
classpath 'com.google.gms:google-services:4.3.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用程序级别的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
def room_version = "2.2.5"
def lifecycle_version = "2.2.0"
def arch_version = "2.1.0"
def coroutines_version = "1.3.5"
def dagger_version = "2.27"
def retrofit_version = "2.8.1"
def interceptor_version = "4.2.1"
def glide_version = "4.11.0"
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.development.allanproject"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude("META-INF/*.kotlin_module")
}
}
kapt {
generateStubs = true
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.2.2'
implementation 'androidx.navigation:navigation-ui:2.2.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
implementation 'com.android.support:multidex:1.0.3'
implementation 'io.reactivex.rxjava2:rxjava:2.2.11'
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
//Retrofit
implementation "com.squareup.retrofit2:retrofit:${retrofit_version}"
implementation "com.squareup.retrofit2:converter-gson:${retrofit_version}"
implementation "com.squareup.retrofit2:adapter-rxjava2:${retrofit_version}"
//http interceptor
implementation "com.squareup.okhttp3:okhttp:${interceptor_version}"
implementation "com.squareup.okhttp3:logging-interceptor:${interceptor_version}"
// Material Dialog Library
implementation 'com.shreyaspatil:MaterialDialog:2.1'
// Material Design Library
implementation 'com.google.android.material:material:1.0.0'
// Lottie Animation Library
implementation 'com.airbnb.android:lottie:3.4.0'
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
// For Kotlin use kapt instead of annotationProcessor
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
//dagger
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
//http interceptor
implementation "com.squareup.okhttp3:okhttp:${interceptor_version}"
implementation "com.squareup.okhttp3:logging-interceptor:${interceptor_version}"
//Glide
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
implementation 'com.google.android.material:material:1.0.0'
//Kodein Dependency Injection
implementation "org.kodein.di:kodein-di-generic-jvm:6.2.1"
implementation "org.kodein.di:kodein-di-framework-android-x:6.2.1"
implementation 'com.github.dhaval2404:imagepicker:1.7.5'
implementation 'com.github.gcacace:signature-pad:1.2.1'
implementation 'com.google.android.gms:play-services:17.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.airbnb.android:lottie:2.7.0'
implementation 'com.github.mayuce:LottieAlertDialog:1.1'
implementation 'com.applandeo:material-calendar-view:1.7.0'
implementation 'com.applandeo:material-calendar-view:1.8.0-rc01'
implementation 'com.applandeo:material-calendar-view:1.9.0-alpha03'
//Rx java
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'
//dexter
implementation 'com.karumi:dexter:6.2.2'
//Location
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.hbb20:ccp:2.4.0'
implementation 'com.github.prabhat1707:EasyWayLocation:2.0'
//Aws
implementation 'com.amazonaws:aws-android-sdk-s3:2.18.0'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.18.0'
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.18.0'
implementation 'com.github.mukeshsolanki:Google-Places-AutoComplete-EditText:0.0.8'
// implementation project(':maplibrary')
implementation 'com.google.android.libraries.places:places:2.2.0'
implementation 'org.jetbrains.anko:anko-support-v4-commons:0.10.8'
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.bitvale:lightprogress:1.0.1'
implementation 'com.github.timigod:android-chat-ui:v0.1.4'
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
implementation 'com.facebook.shimmer:shimmer:0.1.0@aar'
implementation 'com.github.bassaer:chatmessageview:2.0.1'
}
这有很多依赖关系。我建议把你的代码库分成几个子模块,让它们通过接口进行交互。嘿@Jameson,谢谢你的回复,你能用一个例子解释一下吗?