Java 程序类型已存在错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49608409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Program type already present error
提问by Mubashar Rasheed
Although many similar questions exist, I checked the answers to all and none of them worked for me!
尽管存在许多类似的问题,但我检查了所有答案,但没有一个对我有用!
Here is the error I'm facing while compiling the code:
这是我在编译代码时遇到的错误:
Program type already present: android.support.v4.app.BackStackRecord$Op
Message{kind=ERROR, text=Program type already present: android.support.v4.app.BackStackRecord$Op, sources=[Unknown source file], tool name=Optional.of(D8)}
Here is my gradle file:
这是我的gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.narsun.grocery"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
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:cardview-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.github.sd6352051.niftydialogeffects:niftydialogeffects:1.0.0@aar'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup:android-times-square:1.6.5@aar'
implementation 'com.daimajia.slider:library:1.1.5@aar'
implementation 'com.astuetz:pagerslidingtabstrip:1.0.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.myinnos:AwesomeImagePicker:1.0.2'
implementation 'com.github.ratty3697:android-smart-animation-library:1.6'
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
implementation 'com.google.android.exoplayer:exoplayer:2.6.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.10'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
}
You can tell me if there is anything else to add to understand what I'm doing or where I'm wrong.
你可以告诉我是否还有什么要补充的,以了解我在做什么或我哪里错了。
采纳答案by PIXP
Probably the packages versions are not compatible. Try downgrading com.android.support
packages, namely appcompat
可能软件包版本不兼容。尝试降级com.android.support
软件包,即appcompat
so - implementation 'com.android.support:appcompat-v7:27.0.1'
所以 - implementation 'com.android.support:appcompat-v7:27.0.1'
回答by Mubashar Rasheed
For the info for other who will face the same error, I was able to solve my problem by removing the following library from my gradle file:
对于将面临相同错误的其他人的信息,我能够通过从我的 gradle 文件中删除以下库来解决我的问题:
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
This was the library creating issues for me. Thanks
这是图书馆为我创造问题。谢谢
回答by Kevin
In case anyone comes here with a similar issue. In my case it was because I had included an appcompat JAR file in the libs folder as well as having implementation 'com.android.support:appcompat-v7:26.0.0' in my gradle file.
万一有人来这里遇到类似的问题。就我而言,这是因为我在 libs 文件夹中包含了一个 appcompat JAR 文件,并且在我的 gradle 文件中包含了实现 'com.android.support:appcompat-v7:26.0.0'。
When I removed the JAR file, that fixed my issue.
当我删除 JAR 文件时,这解决了我的问题。
回答by Fruit
I want to share how you can understand the error message.
我想分享您如何理解错误消息。
First method, check your dependencies
in build.gradle
:
第一种方法,检查您dependencies
的build.gradle
:
In this case, if I tried to remove that implementation
, the error gone.
在这种情况下,如果我试图删除那个implementation
,错误就消失了。
Second method, Check libs
folder of your app which included .jar files:
第二种方法,检查libs
包含 .jar 文件的应用程序文件夹:
In this case, if I tried to move that .jar to somewhere else, the error gone.
在这种情况下,如果我尝试将该 .jar 移动到其他地方,错误就会消失。
回答by Andi
I'm including a custom aar
in my app/libs
folder, and I correctlyadded the flatLib
object to the root build.gradle
, but incorrectlyadded the '*.aar'
to the fileTree
implementation in the app/build.gradle
:
我aar
在我的app/libs
文件夹中包含了一个自定义,并且我正确地将flatLib
对象添加到了 root build.gradle
,但错误地将 添加'*.aar'
到了 中的fileTree
实现app/build.gradle
:
build.gradle
构建.gradle
allprojects {
repositories {
...
flatDir {
dirs 'libs'
}
}
}
app/build.gradle
应用程序/build.gradle
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'])
^^^
BAD