如何使用支持设计支持库添加多个模块

How to add multiple modules with support design support libraries

我正在开发一个旧项目,它使用两个模块并将它们添加到根项目中,其中一个模块在 build.gradle

中具有此设置
apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.0'

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 21
    }

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:21.0.0'
    compile files('libs/android-support-v7-appcompat.jar')
}

而应用项目有这个

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 22
    buildToolsVersion '22'
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 13
        targetSdkVersion 22
        applicationId 'xxxxxx'
        versionCode xxx
        versionName 'xxx'
        multiDexEnabled false
    }
    signingConfigs {
        release {
            storeFile file("xxxx")
            storePassword "xxx"
            keyAlias "xxx"
            keyPassword "xxxx"
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            ext.enableCrashlytics = true
            signingConfig signingConfigs.release
        }

        debug {
            minifyEnabled true
            ext.enableCrashlytics = true
        }

    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile project(':androidsupportv7appcompat')
    compile(project(":xxxlibraryForActionBar")) {
        exclude module: 'support-v4'
    }

    compile files('libs/commons-io-1.3.2.jar')
    compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
        transitive = true;
    }
    compile 'com.intuit.sdp:sdp-android:1.0.3'
    compile 'com.android.volley:volley:1.0.0'
}

我的根项目有

// 顶级构建文件,您可以在其中添加所有 sub-projects/modules.

通用的配置选项
buildscript {
    repositories {
        jcenter()
    }

    dependencies {

        classpath 'com.android.tools.build:gradle:2.2.3'

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

allprojects {
    repositories {
        jcenter()
    }
}

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

当我更改(在应用程序 build.gradle 中)将 sdk 编译为 23 并将工具构建为 23.0.1 并添加 编译 'com.android.support:design:23.4.0',它给我错误,有一些属性已经定义,我知道它与添加的库之一冲突,这两个库都声明相同的字段,但如何解决。

Error:(268) Attribute "windowActionBar" has already been defined
Error:(268) Attribute "windowActionBarOverlay" has already been defined
Error:(268) Attribute "windowFixedWidthMajor" has already been defined
Error:(268) Attribute "windowFixedWidthMinor" has already been defined
Error:(268) Attribute "windowFixedHeightMinor" has already been defined
Error:(268) Attribute "actionBarTabStyle" has already been defined
Error:(268) Attribute "windowFixedHeightMajor" has already been defined

虽然在将所有内容更新到更新版本之后我得到了

属性 showDivider 已经存在,我发现当 android 合并所有值文件时它是冲突的但找不到任何解决方案,我试图进入 appcompactv7 值文件夹并更改名称showdivider 但这会产生其他问题。

首先,删除两个 build.gradle 文件中的这些依赖项。它们是在Eclipse的样式中添加的,会引起冲突。

compile files('libs/android-support-v7-appcompat.jar')

compile project(':androidsupportv7appcompat')

仅通过在两个 build.gradle 文件中的 dependencies 下添加此行,使用 support-v7 库替换它们。

compile 'com.android.support:support-v7:21.0.0'

此外,您应该考虑替换它,因为我认为它已被弃用。

compile(project(":xxxlibraryForActionBar")) {
    exclude module: 'support-v4'
}

最后你把minSdk设置为7,这样你就连这个依赖都不需要了。所以,你可以删除它。

compile 'com.android.support:support-v4:21.0.0'