2016-11-28 54 views
1

我執行在Android教程這裏的步驟時:https://developer.android.com/training/basics/firstapp/running-app.html「複製資源」運行官方教程

當我這樣做的步驟(在模擬器上運行)「模擬器上運行」,我得到一個錯誤。
我已經雙重檢查了所有的步驟,但看不到有什麼問題。
任何人都可以幫忙嗎?

以下是編譯輸出:

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 
} 

下面是該應用的的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> 
+0

你可以發佈你的'build.gradle'? –

+0

當然,但你可以編輯你自己的問題。添加你的代碼。 –

回答

2

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> 

這不應該是你styles.xml什麼。這些都是字符串,而不是樣式。

此外,錯誤清楚地說"app_name"字符串是重複的。 (強調)

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

如果您在Android Studio中一個全新的項目,你不應該需要在styles.xml文件去改變什麼。

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


作爲參考,styles.xml應該類似於此

<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> 
+0

謝謝。是的,我清楚地看到提到的「app_name」是重複的。我沒有在教程中看到任何關於styles.xml的提及,所以我認爲它必須自動生成。我會在一個小時左右的時間裏更多地學習這個教程。 – eddyq

+0

該文件是自動生成的,是的。我已經添加了'styles.xml'應該看起來像(如果你用'string'資源替換了整個內容) –

+2

我想當教程說要點擊strings.xml時,我無意中單擊了styles.xml。我修好了,謝謝。 – eddyq