错误:重复类:android.support.v7.appcompat.R

时间:2015-03-18 11:47:14

标签: android android-studio

当我尝试编译我的项目时,我收到此错误消息"Error:(9, 14) error: duplicate class: android.support.v7.appcompat.R".我正在使用android studio并且我有最新的SDK包。 gradle for the module:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {

        minSdkVersion 14
        targetSdkVersion 22
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }

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

dependencies {

    compile 'com.android.support:support-v4:22.0.0'
    compile files('libs/commons-codec-1.10.jar')
    compile "com.android.support:appcompat-v7:22.0.0"
}

项目的Gradle文件:

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

这些是项目的gradle文件

1 个答案:

答案 0 :(得分:0)

移动" compileOptions"在你的" defaultConfig"。

之外

我还更新了您的" buildToolsVersion"。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
    }

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

    compileOptions { // <-- Moved this outside of your defaultConfig
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile files('libs/commons-codec-1.10.jar')
    compile 'com.android.support:appcompat-v7:22.0.0' // <-- brings in support-v4
}