"重复资源"在运行官方教程时

时间:2016-11-28 19:33:48

标签: android android-gradle

我在这里执行Android教程中的步骤:https://developer.android.com/training/basics/firstapp/running-app.html

当我执行“#34;在模拟器上运行”#34; (在模拟器上运行),我收到一个错误 我仔细检查了所有步骤,但看不出有什么问题 有人可以帮忙吗?

这是编译输出:

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]
Error:Execution failed for task ':app:mergeDebugResources'.
> [string/app_name] C:\Users\eddyq\AndroidStudioProjects\MyApplication\app\src\main\res\values\strings.xml  [string/app_name] C:\Users\eddyq\AndroidStudioProjects\MyApplication\app\src\main\res\values\styles.xml: Error: Duplicate resources
Information:BUILD FAILED
Information:Total time: 17.608 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

这是项目的build.gradle:

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

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

        // 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
}

以下是app的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
}

这是styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My Application</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
</resources>

这是strings.xml:

<resources>
    <string name="app_name">My Application</string>
</resources>

1 个答案:

答案 0 :(得分:2)

  

这是styles.xml:

UseDeveloperExceptionPage()
UseExceptionHandler()

这不是<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">My Application</string> <string name="edit_message">Enter a message</string> <string name="button_send">Send</string> </resources> 中的内容。无论如何这些都是字符串,而不是样式。

另外,错误清楚地表明styles.xml字符串是重复的。 (强调补充)

  

[ string / app_name ] .. \ app \ src \ main \ res \ values \ strings.xml
    [ string / app_name ] .. \ app \ src \ main \ res \ values \ styles.xml
  错误:资源重复

如果您在Android Studio中创建一个全新的项目,则无需更改"app_name"文件中的任何内容。

I can't find where it says to modify styles.xml anywhere

作为参考,styles.xml看起来与此类似

styles.xml