Gradle构建失败:在中间文件和增量文件中合并冲突

时间:2018-10-20 20:25:42

标签: android android-studio gradle

我创建了一个空的新项目,以找出所有依赖项的问题。 我已将问题缩小为关于生成的代码文件中重复值资源的错误。错误是:

Android resource compilation failed
Output:  C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:561: error: duplicate value for resource 'attr/layout_scrollFlags' with config ''.
C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:561: error: resource previously defined here.
C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:644: error: duplicate value for resource 'attr/behavior_peekHeight' with config ''.
C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:644: error: resource previously defined here.
C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:678: error: duplicate value for resource 'attr/layout_collapseMode' with config ''.
C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:678: error: resource previously defined here.
C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:778: error: duplicate value for resource 'attr/layout_anchorGravity' with config ''.
C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:778: error: resource previously defined here.

Command: C:\Users\Erik\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\ec691f4c746f38f802cb8c84823b8119\aapt2-3.2.1-4818971-windows\aapt2.exe compile --legacy \
        -o \
        C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\res\merged\debug \
        C:\Users\Erik\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0

Erik是我的用户名文件夹。我猜不建议编辑那些文件,因为它们是生成的。

我未成功尝试以下发现的常见解决方案:

  • 将compileSDK更改为<26
  • 删除gradle文件夹
  • 将android.enableAapt2 = false添加到gradle属性中
  • 重新安装Android Studio

我当前的Android Studio版本是3.2.1,我的成绩如下:

项目gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    ext {
        release = [
                versionName: "3.3.0-rc01",
                versionCode: 3300
        ]

        setup = [
                compileSdk: 28 ,
                buildTools: "28.0.3",
                minSdk    : 15,
                targetSdk : 28
        ]

        versions = [
                androidX: '1.0.0',
                //supportLibrary: '27.0.0'
        ]
    }

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    group "com.mikepenz"

    repositories {
        google()
        jcenter()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        //mpAndroid charts
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    roomVersion = '1.0.0'
    archLifecycleVersion = '1.1.1'
    rxJavaVersion = '2.1.7'
    fastAdapterVersion = "3.2.4"
    materializeVersion = "1.1.2"
    butterknife = '8.4.0'
}

应用gradle:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
//wrap with try and catch so the build is working even if the signing stuff is missing
try {
    apply from: '../../../signing.gradle'
} catch (ex) {
}

android {
    compileSdkVersion setup.compileSdk
    buildToolsVersion setup.buildTools

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion setup.minSdk
        targetSdkVersion setup.targetSdk
        versionCode release.versionCode
        versionName release.versionName

        multiDexEnabled true

        setProperty("archivesBaseName", "FastAdapter-v$versionName-c$versionCode")

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }
    }
    buildTypes {
        debug {
            versionNameSuffix "-DEBUG"
            try {
                signingConfig signingConfigs.debug
            } catch (ex) {
            }
            minifyEnabled false
        }
        release {
            try {
                signingConfig signingConfigs.release
            } catch (ex) {
            }
            zipAlignEnabled true
            minifyEnabled false
            //my
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }

    dataBinding {
        enabled = true
    }
}

dependencies {
    //my
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:multidex:1.0.3'

    implementation "androidx.appcompat:appcompat:${versions.androidX}"
    implementation "androidx.recyclerview:recyclerview:${versions.androidX}"
    implementation "androidx.cardview:cardview:${versions.androidX}"
    implementation "com.google.android.material:material:${versions.androidX}"

    //currency
    implementation 'com.jakewharton.threetenabp:threetenabp:1.0.5'
    //serialize colls in db
    implementation 'com.google.code.gson:gson:2.8.2'
    //mpAndroid charts
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

    // Room components
    implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
    annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
    androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"

    // view binding lib?
    implementation 'com.android.support:support-annotations:27.1.1'

    // used to base on some backwards compatible themes
    // contains util classes to support various android versions, and clean up code
    // comes with the awesome "Holder"-Pattern
    // https://github.com/mikepenz/Materialize
    implementation 'com.mikepenz:materialize:1.2.0-rc01'

    // used to provide out of the box icon font support. simplifies development,
    // and provides scalable icons. the core is very very light
    // https://github.com/mikepenz/Android-Iconics
    implementation 'com.mikepenz:iconics-core:3.1.0-rc01'
    implementation "com.mikepenz:iconics-views:3.1.0-rc01"

    //used to generate the drawer on the left
    //https://github.com/mikepenz/MaterialDrawer
    implementation('com.mikepenz:materialdrawer:6.1.0-rc01') {
        transitive = true
        exclude group: "com.mikepenz"
    }
    //used to provide different itemAnimators for the RecyclerView
    //https://github.com/mikepenz/ItemAnimators
    implementation 'com.mikepenz:itemanimators:1.1.0-rc01'
    //used to generate the Open Source section
    //https://github.com/mikepenz/AboutLibraries
    implementation('com.mikepenz:aboutlibraries:6.2.0-rc01') {
        transitive = true
        exclude group: "com.mikepenz"
    }
    //used to display the icons in the drawer
    //https://github.com/mikepenz/Android-Iconics
    implementation 'com.mikepenz:material-design-iconic-typeface:2.2.0.1@aar'
    implementation 'com.mikepenz:community-material-typeface:1.7.22.1@aar'
    implementation 'com.mikepenz:google-material-typeface:3.0.1.1.original@aar'
    implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar'

    //Used for the StickyHeaderSample
    //https://github.com/timehop/sticky-headers-recyclerview
    //original dependency: implementation  'com.timehop.stickyheadersrecyclerview:library:0.4.3@aar'
    //customized version to allow minimal header animation
    implementation 'com.mikepenz.thirdparty:stickyheadersrecyclerview:0.5.1-SNAPSHOT@aar'

    //Used to provide the FastScrollBar
    //https://github.com/krimin-killr21/MaterialScrollBar
    implementation 'com.turingtechnologies.materialscrollbar:lib:10.0.1'

    //https://github.com/JakeWharton/butterknife
    implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

    //used to load the images in the ImageListSample
    //https://github.com/bumptech/glide
    implementation 'com.github.bumptech.glide:glide:3.8.0'

    //Used to provide the drag selection like google photos
    implementation 'com.github.MFlisar:DragSelectRecyclerView:0.2'

    //mopub sdk to showcase the usage of the mopub adapter
    implementation('com.mopub:mopub-sdk:4.7.1@aar') {
        transitive = true
        exclude group: "com.google.android.exoplayer"
    }

    //Used to async operations
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.9'

    configurations.all {
        resolutionStrategy.force "com.mikepenz:materialize:1.2.0-rc01"
        resolutionStrategy.force "com.mikepenz:iconics-core:3.1.0-rc01"
        resolutionStrategy.force "com.mikepenz:aboutlibraries:6.2.0-rc01"
        resolutionStrategy.force "androidx.appcompat:appcompat:${versions.androidX}"
        resolutionStrategy.force "androidx.recyclerview:recyclerview:${versions.androidX}"
        resolutionStrategy.force "androidx.cardview:cardview:${versions.androidX}"
        resolutionStrategy.force "com.google.android.material:material:${versions.androidX}"
    }
}

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:4.1.1"
    }
}

Gradle属性:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

1 个答案:

答案 0 :(得分:0)

我通过两个步骤解决了

1。

android.useAndroidX=true
android.enableJetifier=true

必须置于gradle / project属性(gradle脚本下的文件)中。

2。 省略所有支持库并完全迁移到androidx。为此,请从Gradle中删除支持库依赖项,例如

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.support.v4.whatever version

现在,您的类和布局文件中的许多元素将变为红色。对于他们来说,导入新的androidx导入而忘了旧的v7和v4东西。当心针对较大项目的AndroidX迁移工具,它还不是完美的。感谢您阅读我的问题。