Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program type already present: android.support.v4.app.BackStackState$1

Tags:

android

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.BackStackState$1
Message{kind=ERROR, text=Program type already present: android.support.v4.app.BackStackState$1, sources=[Unknown source file], tool name=Optional.of(D8)}

gradle file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

app gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.guideapp.trickapp"
        minSdkVersion 14
        targetSdkVersion 23

        ndk {
            moduleName "player_shared"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path '../../../Application.mk'
        }
    }
}

dependencies {
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/dagger-1.2.2.jar')
    compile files('libs/javax.inject-1.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/support-v4-19.0.1.jar')
}
like image 483
Divyam Solanki Avatar asked May 31 '18 02:05

Divyam Solanki


2 Answers

Don't use the following:

compile 'com.google.android.gms:play-services:+'

because you must use an exact version of play service. And use only the specific Google Play services APIs your app uses. For example, if you're using location, you only need the following dependency:

implementation 'com.google.android.gms:play-services-location:15.0.1'

read more at Set Up Google Play Services

then change your support library to the same version of your buildToolsVersion. So, you need to change the following:

implementation files('libs/support-v4-19.0.1.jar')

to

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

Remove the support-v4-19.0.1.jar file from your libs directory.

Last, use the same version for the following:

  1. compileSdkVersion
  2. buildToolsVersion
  3. targetSdkVersion

My suggestion, use version 27. So, your app build.gradle will be something like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.guideapp.trickapp"
        minSdkVersion 14
        targetSdkVersion 27

        ndk {
            moduleName "player_shared"
        }
    }

    ...

}

dependencies {
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    compile files('libs/dagger-1.2.2.jar')
    compile files('libs/javax.inject-1.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    implementation 'com.android.support:support-v4:27.1.1'

}
like image 106
ישו אוהב אותך Avatar answered Oct 17 '22 13:10

ישו אוהב אותך


Just add implementation 'com.android.support:support-v4:28.0.0'. Don't forget to change for version you using.

like image 44
Francisco Sales Avatar answered Oct 17 '22 14:10

Francisco Sales