Edr*_*ric 26 android android-studio android-gradle-plugin android-livedata
当我按下Android Studio中的播放按钮时,我的应用程序会编译,但会显示此错误(编辑):
错误:程序类型已存在:android.arch.lifecycle.LiveData
我试过删除.gradle文件夹,然后去Build > Clean Project和Build > Rebuild Project.但是,它不起作用.我也尝试删除源代码,然后再次克隆git并将文件夹导入Android Studio.但是,它仍会产生该错误.
这是我的应用程序app/build.gradle:
Error:Program type already present: android.arch.lifecycle.LiveData
Run Code Online (Sandbox Code Playgroud)
Hoo*_*net 25
当我提出支持库版本时,我今天遇到了同样的问题.
尝试用'27 .0.2' 替换所有 '27 .1.0'
后来我确实设法通过升级其他库来删除错误.这是我目前的工作状态: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" }
}
}
Run Code Online (Sandbox Code Playgroud)
////////////////// 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'
}
}
Run Code Online (Sandbox Code Playgroud)
///////////////
我还将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
Run Code Online (Sandbox Code Playgroud)
Ell*_*lar 21
这篇文章是非常相似的错误的顶级搜索结果:"程序类型已存在: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'
Run Code Online (Sandbox Code Playgroud)
至:
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'
Run Code Online (Sandbox Code Playgroud)
---更新的答案---
我之前的回答是为了解决这个错误.但是,我认为使用最佳实践再次呈现它是值得的:
应用级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"
Run Code Online (Sandbox Code Playgroud)
项目级build.gradle文件:
ext {
roomVersion = '1.1.1'
archLifecycleVersion = '1.1.1'
}
Run Code Online (Sandbox Code Playgroud)
参考:https:
//codelabs.developers.google.com/codelabs/android-room-with-a-view/#2
| 归档时间: |
|
| 查看次数: |
28317 次 |
| 最近记录: |