gpt4 book ai didi

android - 运行官方教程时"Duplicate resources"

转载 作者:行者123 更新时间:2023-11-29 19:28:24 25 4
gpt4 key购买 nike

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

当我执行“Run on an Emulator”(在模拟器上运行)的步骤时,出现错误。
我已经仔细检查了所有步骤,但看不出有什么问题。
谁能帮忙?

编译结果如下:

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>

最佳答案

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>

关于android - 运行官方教程时"Duplicate resources",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40852079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com