Android 工作室自动生成的 xml 文件有错误

Android studio autogenerated xml file has error

更新到 android studio 2.2 后,出现错误 (--debug):

Error:20:20:53.047 [ERROR] [org.gradle.api.Project] AGPBI: {"kind":"error","text":"Tag \u003cwrapItem\u003e can not appear inside \u003cstyle\u003e, only \u003citem\u003e","sources":[{"file":"C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\merged\debug\values\values.xml","position":{"startLine":354}}],"original":"","tool":"AAPT"}
20:20:53.048 [ERROR] [org.gradle.api.Project] C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\merged\debug\values\values.xml:355: error: Tag <wrapItem> can not appear inside <style>, only <item>

20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] 
20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] 
20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] * Whenter code hereat went wrong:
20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':app:processDebugResources'.
20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] > com.android.ide.common.process.ProcessException: Failed to execute aapt
20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] 
20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
20:20:53.051 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. 

堆栈跟踪:

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2421Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72421Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCompat2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUi2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUtils2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportFragment2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportMediaCompat2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2421Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources
AGPBI: {"kind":"error","text":"Tag \u003cwrapItem\u003e can not appear inside \u003cstyle\u003e, only \u003citem\u003e","sources":[{"file":"C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\merged\debug\values\values.xml","position":{"startLine":354}}],"original":"","tool":"AAPT"}
C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\merged\debug\values\values.xml:355: error: Tag <wrapItem> can not appear inside <style>, only <item>



 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugResources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access[=13=]0(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:153)
    at org.gradle.internal.Factories.create(Factories.java:22)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:150)
    at org.gradle.initialization.DefaultGradleLauncher.access0(DefaultGradleLauncher.java:32)
    at org.gradle.initialization.DefaultGradleLauncher.create(DefaultGradleLauncher.java:98)
    at org.gradle.initialization.DefaultGradleLauncher.create(DefaultGradleLauncher.java:92)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:92)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:83)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:99)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:46)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:58)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:48)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:81)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:46)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:52)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator.run(DaemonStateCoordinator.java:237)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: Failed to execute aapt
    at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:185)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:82)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:245)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:232)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 70 more
Caused by: com.android.ide.common.process.ProcessException: Failed to execute aapt
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:909)
    at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:178)
    ... 78 more
Caused by: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing 'C:\Users\Dan\AppData\Local\Android\sdk\build-tools.0.3\aapt.exe' with arguments {package -f --no-crunch -I C:\Users\Dan\AppData\Local\Android\sdk\platforms\android-24\android.jar -M C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\merged\debug -m -J C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\generated\source\r\debug -F C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\resources-debug.ap_ --debug-mode --custom-package com.example.dan.myordersystem -0 apk --preferred-density hdpi --output-text-symbols C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\symbols\debug --no-version-vectors}
    at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
    at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:907)
    ... 79 more
Caused by: com.android.ide.common.process.ProcessException: Error while executing 'C:\Users\Dan\AppData\Local\Android\sdk\build-tools.0.3\aapt.exe' with arguments {package -f --no-crunch -I C:\Users\Dan\AppData\Local\Android\sdk\platforms\android-24\android.jar -M C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\merged\debug -m -J C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\generated\source\r\debug -F C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\resources-debug.ap_ --debug-mode --custom-package com.example.dan.myordersystem -0 apk --preferred-density hdpi --output-text-symbols C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\symbols\debug --no-version-vectors}
    at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:75)
    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:49)
    at com.android.builder.internal.aapt.AbstractProcessExecutionAapt.onSuccess(AbstractProcessExecutionAapt.java:78)
    at com.android.builder.internal.aapt.AbstractProcessExecutionAapt.onSuccess(AbstractProcessExecutionAapt.java:74)
    at com.google.common.util.concurrent.Futures.run(Futures.java:1319)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:457)
    at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156)
    at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145)
    at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185)
    at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
    at com.android.build.gradle.internal.process.GradleProcessExecutor.run(GradleProcessExecutor.java:58)
Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Dan\AppData\Local\Android\sdk\build-tools.0.3\aapt.exe'' finished with non-zero exit value 1
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:367)
    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:47)
    ... 9 more


BUILD FAILED

Total time: 1.128 secs

错误显然在 values.xml C:\Users\Dan\AndroidStudioProjects\myOrderSystem\app\build\intermediates\res\merged\debug\values\values.xml:355: error: Tag <wrapItem> can not appear inside <style>, only <item>

这就是错误所在(在 values.xml 中):

......
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <wrapItem name="colorPrimary">@color/colorPrimary</wrapItem>
    <wrapItem name="colorPrimaryDark">@color/colorPrimaryDark</wrapItem>
    <wrapItem name="colorAccent">@color/colorAccent</wrapItem>
</style>
......

如果删除了,构建后会被某些东西重新生成。不幸的是,我找不到生成 values.xml.

的文件

这里是 build.gradle(模块:app):

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.3'
    repositories{
        jcenter()
    }
    defaultConfig {
        applicationId "com.example.dan.myordersystem"
        minSdkVersion 11
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
//    compile 'com.google.code.gson:gson:2.3.1'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/gcm.jar')
//    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
}

问题是我不能直接修改values.xml。每次我构建项目时,values.xml 只是 恢复 到相同的错误代码。似乎 重新生成 values.xml 在构建 之后,所以我应该找到一些方法来更改 values.xml 但我没有知道怎么做。

有人有什么想法吗?请帮忙。

Please try this.

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

如果你的错误在这里

这就是错误所在(values.xml):

......
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <wrapItem name="colorPrimary">@color/colorPrimary</wrapItem>
    <wrapItem name="colorPrimaryDark">@color/colorPrimaryDark</wrapItem>
    <wrapItem name="colorAccent">@color/colorAccent</wrapItem>
</style>
......

那么实际的错误是在style.xml文件中,在res > value > style.xml

您的应用主题似乎有问题。正如用户 iasoftsolutions 所说,尝试将 <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
更改为 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

看看是否有帮助。

感谢您的回答。 虽然我解决了问题,但没有找到答案。我只是创建另一个新项目,并按字面意思创建与旧项目同名的文件。然后,检查旧代码并复制到新文件。我花了很长时间。我发现了一些有趣的东西。某些 xml 文件中的某些键码 "item" 被修改为“wrapItem”。好像更新项目的时候出了点问题。

无法复制文件。 (copy files: all .java files, gradle files, and manifest)直接复制文件也会出现同样的问题。

从现在开始,我可以说,"I kind of scare updating project..."