eddyq eddyq - 7 days ago 5
Android Question

"Duplicate resources" when running official tutorial

I'm performing the steps in an Android tutorial here: https://developer.android.com/training/basics/firstapp/running-app.html

When I do the step to "Run on an Emulator" (running on the emulator), I get an error.

I have double checked all the steps, but can't see what is wrong.

Can anyone help?

Here is the compile output:

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


Here is the build.gradle for the project:

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


Here is the build.gradle for the app:

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


Here is 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>


Here is strings.xml:

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

Answer

Here is 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>

This isn't what should be in your styles.xml. Those are strings anyways, not styles.

Plus, the error clearly says the "app_name" string is duplicated. (Emphasis added)

[string/app_name] ..\app\src\main\res\values\ strings.xml
[string/app_name] ..\app\src\main\res\values\ styles.xml
Error: Duplicate resources

If you make a brand new project in Android Studio, you should not need to change anything in the styles.xml files.

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


For reference, the styles.xml should look similar to this

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/PrimaryColor</item>
        <item name="colorPrimaryDark">@color/PrimaryDarkColor</item>
        <!-- Customize your theme here. -->
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
</resources>
Comments