Android studio show this error during run. Error:

2020-07-24 04:14发布

问题:

im tried to run my android app program through / using android studio version 3.1.4 and i have no idea what is happen while im run my program its keep showing this error

Error: Program type already present: androidx.concurrent.futures.DirectExecutor

I'd tried quick googling its answer but yet still not found answer related to my issues.

As per I'd found those issues related to class name conflict? Correct me if I'm wrong.

Below this is my build.gradle

            apply plugin: 'com.android.application'
            apply plugin: 'com.google.protobuf'

            android {
            compileSdkVersion 28
            defaultConfig {
                applicationId "com.ikan.elogbook"
                minSdkVersion 24
                targetSdkVersion 28
                versionCode 1
                versionName "1.0"

            testInstrumentationRunner"androidx.test.runner.AndroidJUnitRunner"


            }


            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro'
                }
            }

            lintOptions {

            disable'GoogleAppIndexingWarning','HardcodedText','InvalidPackage'
                textReport true
                textOutput "stdout"
            }

            allprojects {
                repositories {
                    maven { url 'https://jitpack.io' }

                    //this line added to resolve issue some grpc package / 
            library are not found
                    //reference bug url https://github.com/grpc/grpc- 
            java/issues/4460
                    mavenCentral()
                }
            }
}

    ext {
        supportLibraryVersion = "25.3.1"
    }


        protobuf {
            protoc { artifact = 'com.google.protobuf:protoc:3.5.1-1' }
            plugins {
            javalite { artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0" }
            grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.17.1' // CURRENT_GRPC_VERSION
            }
        }
        generateProtoTasks {
            all().each { task ->
                task.plugins {
                    javalite {}
                    grpc { // Options added to --grpc_out
                        option 'lite' }
                }
            }
        }
}

dependencies {

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
    implementation 'com.github.jkwiecien:EasyImage:1.3.1'
    implementation 'com.mikepenz:materialdrawer:6.1.1'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.annotation:annotation:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'de.codecrafters.tableview:tableview:2.8.0'
    implementation 'com.pixplicity.easyprefs:library:1.9.0'
    // You need to build grpc-java to obtain these libraries below.
    implementation 'io.grpc:grpc-okhttp:1.17.1'
    // CURRENT_GRPC_VERSION
    implementation 'io.grpc:grpc-protobuf-lite:1.17.1'
    // CURRENT_GRPC_VERSION
    implementation 'io.grpc:grpc-stub:1.17.1'
    // CURRENT_GRPC_VERSION
    implementation 'javax.annotation:javax.annotation-api:1.2'
    protobuf 'com.google.protobuf:protobuf-java:3.5.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1-alpha01'
}

回答1:

When different types of dependency present in build.gradle file like

implementation 'com.android.support:appcompat-v7:27.1.0'

and

implementation 'com.android.support:design:28.0.0'

or version conflictibility.

to avoid this you need to maintain the version of your dependency like this

  implementation 'com.android.support:appcompat-v7:27.1.0'
  implementation 'com.android.support:design:28.0.0'

you can also refer this link to know why this error occurs

What is "Program type already present"?