Program type already present: android.support.v4.a

2019-01-16 12:20发布

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.

9条回答
祖国的老花朵
2楼-- · 2019-01-16 12:47

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
查看更多
迷人小祖宗
3楼-- · 2019-01-16 12:53

The put this below gradle

implementation 'com.android.support:support-v4:27.1.1'

查看更多
姐就是有狂的资本
4楼-- · 2019-01-16 12:54

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?"

查看更多
趁早两清
5楼-- · 2019-01-16 12:57

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'
查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-16 13:04

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

查看更多
做个烂人
7楼-- · 2019-01-16 13:06

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.

查看更多
登录 后发表回答