可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have upgraded my android studio .. and I found many problems in the latest version
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
project:
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.alcantara.bugismart"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
implementation 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'
}
You can tell me if there is anything else to add to understand what I'm doing or where I'm wrong.
回答1:
The problem probably because of duplicated support library. This dependency:
implementation 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'
is using old version of support library. Try excluding the support library with:
implementation ('com.github.ViksaaSkool:AwesomeSplash:v1.0.0') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
exclude module: 'support-v4'
}
You need to check your dependencies with the following command:
./gradlew app:dependencies
回答2:
The put this below gradle
implementation 'com.android.support:support-v4:27.1.1'
回答3:
An alternative to the accepted answer is to tell gradle to force the newer version:
final SUPPORT_LIB_VER = '27.1.1'
configurations.all {
resolutionStrategy {
force "com.android.support:appcompat-v7:${SUPPORT_LIB_VER}"
force "com.android.support:support-v4:${SUPPORT_LIB_VER}"
}
}
This can be more convenient when you have many dependencies.
see also: Answer to "How can I force Gradle to set the same version for two dependencies?"
回答4:
In your dependencies section in gradle
Add this Code
implementation 'com.android.support:support-v4:28.0.0'
回答5:
Also check your libs folder because
implementation fileTree(dir: 'libs', include: ['*.jar'])
will pick all jars from there too. You might have jars duplicating each other or your lower implementations.
I had duplicates in my libs and got this problem.
回答6:
multiDexEnabled true
add the line above in android block in gradle-app its work for me ...
回答7:
replace you dependencies with it.
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
回答8:
Add this code to gradle (According to "SdkVersion")
implementation 'com.android.support:support-v4:28.0.0-beta01'
for example my SDKVersion is 28 then I use this code :
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
implementation 'com.android.support:support-v4:28.0.0-beta01'
回答9:
enter image description here
I tried those :
- clean / rebuild
- Invalidate cash and restart
- Exclude dependencies from my library in my app.gradle (see below)
implementation (project(':libxmiimp')) {exclude group: 'com.android.support', module: 'support-v4'}
- Playing with gradle settings (things like multiDex enable true and other)
But my probleme was that Android-support-v4.jar somehow got into my local android library`s lib folder....
Deleting it fixed my problem