Android studio自动生成的xml文件有错误

时间:2016-10-18 12:21:55

标签: java android xml android-studio-2.2

更新到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. 

stacktrace:

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$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.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$4.run(DefaultGradleLauncher.java:153)
    at org.gradle.internal.Factories$1.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.access$200(DefaultGradleLauncher.java:32)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:98)
    at org.gradle.initialization.DefaultGradleLauncher$1.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$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.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$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:237)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.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\24.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\24.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$1.onSuccess(AbstractProcessExecutionAapt.java:78)
    at com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:74)
    at com.google.common.util.concurrent.Futures$6.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$1.run(GradleProcessExecutor.java:58)
Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Dan\AppData\Local\Android\sdk\build-tools\24.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(Module: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但我不知道如何。

有没有人有任何想法?请帮忙。

3 个答案:

答案 0 :(得分:0)

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>

答案 1 :(得分:0)

如果您的错误在这里

这就是错误所在的位置(在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&gt;下值&gt; style.xml

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

看看是否有帮助。

答案 2 :(得分:0)

感谢您的回答。 虽然我解决了问题,但没有找到答案。我只是创建另一个新项目,并逐字地创建与旧项目同名的文件。然后,检查旧代码并复制到新文件。我花了很长时间。我找到了一些有趣的东西。某些xml文件中的某些键代码“item”被修改为“ wrapItem ”。看起来在更新项目时发生了一些错误。

无法复制文件。 (复制文件:所有.java文件,gradle文件和清单)直接复制文件会导致同样的问题。

从现在开始,我可以说,“我有点害怕更新项目......”