我正在开发新闻应用程序,但是在gradle控制台中出现以下错误
(androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class androidx.core.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class androidx.core.internal.package-info found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class androidx.versionedparcelable.CustomVersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.NonParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelImpl found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelImpl$1 found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelUtils found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel$1 found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel$ParcelException found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelParcel found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream$FieldBuffer found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream$InputBuffer found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelize found in modules class
在我的app.gradle下面
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation 'com.github.bassaer:chatmessageview:2.0.1'
implementation 'com.google.code.gson:gson:2.8.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
答案 0 :(得分:8)
您需要在gradle.properties中编写此代码
android.useAndroidX=true
android.enableJetifier=true
答案 1 :(得分:5)
我遇到了同样的问题,我就是这样解决的
展开 Gradle Scripts,然后转到 graddle.properties 并添加这两行
注意:也许第一行 android.useAndroidX=true 已经存在,所以不要重复。
android.useAndroidX=true android.enableJetifier=true
答案 2 :(得分:4)
将这些行添加到gradle.properties文件中可解决“重复类”错误:
android.useAndroidX=true
android.enableJetifier=true
但是,这在我的项目中产生了新的错误:
“软件包android.support.annotation不存在”
“找不到符号类片段”
“程序包android.support.v4.content不存在”
“程序类型已经存在”
等
但是,重构对我有用:
Migrate your project to AndroidX by selecting Refactor >
"Migrate to AndroidX" from the menu bar.
Select Build > Clean project
Restore Android Studio
现在,我的项目(Match4app)可与AndroidX一起使用,并且能够在PlayStore中发布它而没有任何问题。
注释:此任务还使我能够升级所有其他依赖AndroidX的库(即com.firebaseui:firebase-ui-auth:6.0.2,com.google.android.gms:play-services-games:18.0 .1,com.google.android.gms:play-services-auth:17.0.0,com.google.android.gms:play-services-ads:18.2.0等)。
答案 3 :(得分:2)
我遇到了类似的情况,以下内容基于我的other answer:
您的项目(或其子项目之一)在末尾使用 + 加号来引用依赖项,例如com.google.firebase:firebase-auth:+
,这意味着使用任何更高版本在可能的情况下,该较新版本不再使用android.support
库,而是使用androidx
;要解决此问题,请按照以下步骤操作。
ANDROID_HOME
环境变量,然后打开控制台窗口(如git-bash,因为它保留了整个命令的输出),并且将cd
放入您的{{1} }目录(对于Ionic项目,应为android
)。platforms/android
./gradlew :app:dependencies
。androidx
或 16.0.8 -> 19.0.0
,这都表示该版本是自动解析的(由于 + ,该版本比您指定的版本高)。+ -> 19.0.0
控制台,而是第一步)。要强制特定版本的依赖项,请在您的clear
根文件中添加以下内容(对我有用),但是当然请在下面进行编辑并添加自己的规则(因为这些可能不适用于您的情况):
build.gradle
答案 4 :(得分:1)
取自here。 AndroidX是Android团队用来在Jetpack中开发,测试,打包,版本和发布库的开源项目。
答案 5 :(得分:1)
就像@Ahmed所说,解决方案是实现AndroidX,它对我有用。但是,这不是一个简单的方法,需要一些耐心...这些是我做的步骤:
首先,非常重要是您在其他分支中进行了所有这些更改,还是对项目进行了备份。
您需要拥有Android Gradle插件版本3.5.1。因此,在 build.gradle 中设置:dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
...
完成后,它已经完成了所有相关的修改,但是由于发现任何错误,有可能您无法正确部署项目。这些是我发现的问题和解决方案:
如果使用 Kotlin ,请在build.gradle中设置:buildscript {
ext.kotlin_version = '1.3.10'
...
和compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
destination file("$reportsDir/checkstyle/checkstyle.xml")
答案 6 :(得分:0)
仅当您可以降级到特定版本时,顶级大师的答案才有效。就我而言,我有一个React Native应用,并且我正在使用的库之一已迁移到AndroidX。以前的版本存在iOS问题,因此我必须使用最新版本。我要做的是:
node_module
依赖项转换为AndroidX。对于React Native 0.60及更高版本,jetify是自动运行的,因此您无需安装此库。