Android Studio - การรวบรวม Gradle ล้มเหลว

การคอมไพล์ของฉันล้มเหลวด้วยเหตุผลบางประการ แต่ก่อนหน้านี้มันทำงานได้ดี

นี่เป็นข้อผิดพลาดที่ฉันได้รับเมื่อพยายามรวบรวมโครงการ:

Program type already present: android.support.design.widget.CoordinatorLayout$Behavior
Message{kind=ERROR, text=Program type already present: android.support.design.widget.CoordinatorLayout$Behavior, sources=[Unknown source file], tool name=Optional.of(D8)}

(สร้าง) app.iml :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "appjoe.wordpress.com.testdemo"
        minSdkVersion 23
        targetSdkVersion 26
        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(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:26.1.0'
    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'
    implementation 'com.android.support:design:26.1.0'

    // picasso and volley
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'eu.the4thfloor.volley:com.android.volley:2015.05.28'

    // retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    // rxjava & rxandroid
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.16'

    // glide
    implementation 'com.github.bumptech.glide:glide:4.7.1'

    // android views
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
}

ฉันยังได้รับข้อผิดพลาดสำหรับการขึ้นต่อกันครั้งที่สองในพื้นที่การขึ้นต่อกันโดยแจ้งว่า:

ไลบรารี com.android.support ทั้งหมดต้องใช้ข้อกำหนดเวอร์ชันเดียวกันทุกประการ (เวอร์ชันผสมกันอาจทำให้เกิดปัญหารันไทม์ได้) พบเวอร์ชัน 27.1.1, 27.1.0, 26.1.0 ตัวอย่าง ได้แก่ com.android.support:support-compat:27.1.1 และ com.android.support:exifinterface:27.1.0 น้อยกว่า... (Ctrl+1)

มีไลบรารีหรือเครื่องมือและไลบรารีบางอย่างรวมกันซึ่งเข้ากันไม่ได้หรืออาจทำให้เกิดข้อบกพร่องได้ ความเข้ากันไม่ได้ประการหนึ่งคือการคอมไพล์กับเวอร์ชันของไลบรารีสนับสนุน Android ที่ไม่ใช่เวอร์ชันล่าสุด (หรือโดยเฉพาะ เวอร์ชันที่ต่ำกว่า targetSdkVersion ของคุณ)


person Apurv    schedule 21.07.2018    source แหล่งที่มา
comment
เปลี่ยนการพึ่งพาการร่อนของคุณเป็นสิ่งนี้ - การใช้งาน 'com.github.bumptech.glide:glide:4.0.0'   -  person Rohit Suthar    schedule 21.07.2018
comment
ดูคำตอบนี้: stackoverflow.com/a/51415063/6672577   -  person Shahzad Afridi    schedule 21.07.2018
comment
เปลี่ยนไลบรารีการสนับสนุนของคุณเวอร์ชัน 27.1.1 และเปลี่ยนการคอมไพล์ sdk เวอร์ชัน 27 ด้วย   -  person Shahzad Afridi    schedule 21.07.2018
comment
@RohitSuthar ขอบคุณมันได้ผล ฉันจะปิดคำถามนี้ได้อย่างไร   -  person Apurv    schedule 22.07.2018


คำตอบ (1)


นี่เป็นเพราะว่าในการพึ่งพาบางไลบรารี (นอกเหนือจากไลบรารีสนับสนุน) ได้ใช้ไลบรารีเวอร์ชันที่รองรับที่แตกต่างจากของคุณ นั่นคือสาเหตุที่ทำให้คุณได้รับข้อผิดพลาดนี้ คุณได้อ้างอิงไลบรารีการสนับสนุนแบบผสมเวอร์ชัน 26 และ 27

ดังนั้น คุณต้องใช้ไลบรารีการสนับสนุนที่ตรงกันซึ่งเป็นเวอร์ชัน 27.1.1 เปลี่ยน build.gradle ของคุณเป็นดังนี้:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27 // use version 27
    defaultConfig {
        applicationId "appjoe.wordpress.com.testdemo"
        minSdkVersion 23
        targetSdkVersion 27 // targeting api version 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(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:27.1.1'
    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'
    implementation 'com.android.support:design:27.1.1'

    // picasso and volley
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'eu.the4thfloor.volley:com.android.volley:2015.05.28'

    // retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    // rxjava & rxandroid
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.16'

    // glide
    implementation 'com.github.bumptech.glide:glide:4.7.1'

    // android views
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
}

หรือ

อัปเกรดเวอร์ชันไลบรารีของคุณเป็นเวอร์ชันใหม่ เพียงวางเคอร์เซอร์ไว้ที่แต่ละไลบรารี Android studio จะบอกคุณเองว่าไลบรารีนี้มีเวอร์ชันใหม่ให้ใช้งาน

person Shahzad Afridi    schedule 21.07.2018