当我在Android Studio中按播放按钮时,我的应用程序会编译,但会显示此错误(已编辑):
错误:程序类型已存在:android.arch.lifecycle.LiveData
我尝试删除.gradle
文件夹,然后转到Build > Clean Project
和Build > Rebuilt Project
。但是,它不起作用。我还尝试删除源代码,然后再次从git
克隆并将文件夹导入Android Studio。但是,它仍然会产生错误。
这是我的应用app/build.gradle
:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.edricchan.studybuddy"
minSdkVersion 24
targetSdkVersion 27
versionCode 8
versionName "1.0.0-rc.503"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "en"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:support-annotations:27.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
testImplementation 'junit:junit:4.12'
// Firebase stuff
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.google.firebase:firebase-firestore:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.android.gms:play-services-auth:11.8.0'
implementation 'com.firebaseui:firebase-ui-auth:3.1.0'
implementation 'com.firebaseui:firebase-ui-firestore:3.1.0'
implementation 'com.firebaseui:firebase-ui-storage:3.1.0'
// Provide a way to update the app
implementation 'com.github.javiersantos:AppUpdater:2.6.4'
// Chrome Custom Tabs
implementation 'com.android.support:customtabs:27.1.0'
// The app's intro screen
implementation 'com.heinrichreimersoftware:material-intro:1.6.2'
// Use for new Material Text field boxes recently introduced
implementation 'com.github.HITGIF:TextFieldBoxes:1.3.7'
// Report an issue to Github without having to open a new tab and so on...
implementation 'com.heinrichreimersoftware:android-issue-reporter:1.3.1'
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:26)
显然,这是预期的行为:
com.firebaseui:firebase-ui-firestore:3.1.0依赖于android.arch.lifecycle:extensions:1.0.0-beta1。切换到版本3.2.2通过使用支持库27.1.0构建的Lifecycle 1.1库来修复此问题。 - Issue Tracker
对我来说,删除firebase-ui
依赖项解决了这个问题,因为我甚至没有首先使用该库。
答案 1 :(得分:25)
今天,当我提出支持库版本时,我遇到了同样的问题。
尝试将'strong>所有 '27 .1.0'替换为'27 .0.2'
后来我确实设法通过升级其他库来删除错误。 这是我目前的工作状态: root gradle:
buildscript {
ext.kotlin_version = '1.2.21'
ext.support_version = '27.1.0'
ext.anko_version = '0.10.4'
ext.android_plugin_version = '3.0.1'
ext.google_services_version = '11.8.0'
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath 'com.android.tools.build:gradle:3.1.0-beta4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
////////////////// app gradle libraries:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
transitive = true
}
// kotlin:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.anko:anko-common:$anko_version"
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.3'
// support libraries:
implementation "com.android.support:recyclerview-v7:$support_version"
implementation "com.android.support:support-v4:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:cardview-v7:$support_version"
implementation "com.android.support:support-vector-drawable:$support_version"
// misc:
implementation 'com.github.d-max:spots-dialog:0.7@aar'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta5'
implementation 'com.backendless:backendless:4.4.0'
implementation 'io.nlopez.smartlocation:library:3.3.3'
// Google services:
implementation "com.google.firebase:firebase-core:$google_services_version"
implementation "com.google.firebase:firebase-auth:$google_services_version"
implementation 'com.firebaseui:firebase-ui-auth:3.2.2'
implementation "com.google.android.gms:play-services-location:$google_services_version"
implementation "com.google.android.gms:play-services-auth:$google_services_version"
implementation('com.google.api-client:google-api-client:1.23.0') {
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}
}
///////////////
我还将graddle-wrapper.properties升级为:
#Wed Dec 20 15:08:34 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
答案 2 :(得分:19)
此帖子是最相似错误的顶部搜索结果:“程序类型已存在:android.arch.lifecycle。 ViewModelProvider $ Factory ”
我的项目使用Room和LiveData,但不使用Firebase。以下更改消除了该错误:
从:
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
implementation 'android.arch.lifecycle:extensions:1.0.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
收件人:
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
implementation 'android.arch.lifecycle:extensions:1.1.1'
annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'
---更新的答案---
我先前的答案旨在解决此错误。但是,我认为最好用最佳实践再次介绍它:
应用程序级别的build.gradle文件:
// Room components
implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
项目级别的build.gradle文件:
ext {
roomVersion = '1.1.1'
archLifecycleVersion = '1.1.1'
}
参考:
https://codelabs.developers.google.com/codelabs/android-room-with-a-view/#2
答案 3 :(得分:3)
Firebase-UI 3.1.0与Firebase / Google Services 11.8.0不兼容
升级或降级希望这个帮助;)
答案 4 :(得分:2)
我也在原始问题中发布了错误,即:
Error:Program type already present: android.arch.lifecycle.LiveData
目前还不清楚哪些库导致了问题。从@lienmt上面的提示我意识到它可能与Firebase有关。
就我而言,我使用的是Firebase,并且还使用了firebase-ui库3.2.2:
implementation 'com.firebaseui:firebase-ui-database:3.2.2'
我已将所有其他Firebase库升级到15.0.0,但实现了我的firebase-ui库不兼容并在此处确认:
请务必将您的firebase-ui版本与针对其进行配对的Firebase版本进行匹配。
将我的firebase-ui版本压缩到3.3.1是解决错误的原因:
implementation 'com.firebaseui:firebase-ui-database:3.3.1'
此处参考的是我现在使用的版本,我的应用程序正在运行且没有错误:
implementation 'com.google.android.gms:play-services-wearable:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-database:15.0.0'
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.firebase:firebase-auth:15.0.0'
implementation 'com.google.firebase:firebase-messaging:15.0.0'
implementation 'com.firebaseui:firebase-ui-database:3.3.1'
答案 5 :(得分:1)
请在您的应用程序build.gradel文件中添加以下依赖项
implementation "android.arch.core:runtime:1.1.1"
implementation "android.arch.core:common:1.1.1"
答案 6 :(得分:0)
@Edric:因为我无法重播帖子中的图片,我在这里回答你的问题。
对我有用的变化:
PS:我还将gradle-wrapper.properties中的distributionUrl升级为 http://services.gradle.org/distributions/gradle-4.6-all.zip
答案 7 :(得分:0)
就像Edric所提到的,发生这种情况是因为某些库仍使用android.arch.lifecycle:extensions库的旧版本,即android.arch.lifecycle:extensions:1.0.0
。
一种解决方法是强制应用程序使用该库的相同版本(如果可以,请使用最新版本)。
有两种方法可以做到这一点:
在“依赖关系”部分下明确定义了我们要在Gradle中使用的库版本。
implementation 'android.arch.lifecycle:extensions:1.1.1
或
该库的强制解析,也位于dependencies
下。
android {
configurations.all {
resolutionStrategy.force 'android.arch.lifecycle:extensions:1.1.1'
}
}
答案 8 :(得分:0)
就我而言,将targetSdkVersion
和compileSdkVersion
提升到28,并使用所有支持库的28版解决了该问题。
我在升级Glide时遇到了这个问题。我遇到关于duplicate CoordinatorLayout的错误。我通过使用com.android.support:design:27.1.0
solved来实现,但是随后又遇到了关于LiveData$LifecycleBoundObserver
的另一个错误。
几个小时后,我放弃了targetSdkVersion
和compileSdkVersion
并将其升级到API 28,并使用
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
因为YOLO。运气不好,它起作用了。
答案 9 :(得分:0)
只需升级即可。对我来说,我必须在App build.gradle文件中升级以下文件:
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.firebaseui:firebase-ui-database:3.2.2'
然后,您将同步文件。运行时,您会收到新的安装失败弹出框对话框。只需取消这些,然后执行以下操作即可:
1) Build -> Clean Project
2) Build -> Build Bundle(s) / APK(s) -> Build APK(s)
3) Run your project! Should work!
如果您想了解我如何解决此问题的其他详细信息,请遵循此link,但这可以解决问题!