java 错误:资源 android:attr/preserveIconSpacing 是私有的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49848930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 10:28:00  来源:igfitidea点击:

Error: resource android:attr/preserveIconSpacing is private

javaandroidandroid-studiogradleandroid-gradle-plugin

提问by Wan999

Hi i am trying to migrate my Android app project from Eclipse to Android Studio. This built for Android KitKat. I forgot what is the version of Eclipse that i used. Im using Android Studio 3.0.1. I followed the instruction from here https://developer.android.com/studio/intro/migrate.html. I got this error when trying to migrate. Please help. This means a lot to me

嗨,我正在尝试将我的 Android 应用程序项目从 Eclipse 迁移到 Android Studio。这是为 Android KitKat 构建的。我忘记了我使用的 Eclipse 版本是什么。我使用的是 Android Studio 3.0.1。我按照这里https://developer.android.com/studio/intro/migrate.html的说明进行操作。尝试迁移时出现此错误。请帮忙。这对我来说意义重大

Error Message Image

错误信息图片

And this is the error message on the Gradle Console

这是 Gradle 控制台上的错误消息

Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]

Configuration on demand is an incubating feature.
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
:app:preBuild UP-TO-DATE
:app:preDebugBuild
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:checkDebugManifest
:app:generateDebugBuildConfig
:app:prepareLintJar
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:createDebugCompatibleScreenManifests
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug
:app:processDebugResources
AGPBI: {"kind":"error","text":"error: resource android:attr/preserveIconSpacing is private.","sources":[{"file":"C:\Users\Shazwan\.gradle\caches\transforms-1\files-1.1\appcompat-v7-19.1.0.aar\df4f4f2e7a9c43dda4827c11e87fed2a\res\values\values.xml","position":{"startLine":507,"startColumn":4,"startOffset":24529,"endColumn":61,"endOffset":24586}}],"original":"","tool":"AAPT"}
D:\Work\AndroidD\OpacKAWAT\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:133: error: resource android:attr/preserveIconSpacing is private.
error: failed linking references.

Failed to execute aapt
com.android.ide.common.process.ProcessException: Failed to execute aapt
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:796)
    at com.android.build.gradle.tasks.ProcessAndroidResources.invokeAaptForSplit(ProcessAndroidResources.java:551)
    at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:285)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.run(ExecuteActionsTaskExecuter.java:122)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.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:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access0(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
    at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)
    at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
    at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:794)
    ... 48 more
Caused by: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
    at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:462)
    at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
    at com.android.builder.internal.aapt.v2.QueueableAapt2.lambda$makeValidatedPackage(QueueableAapt2.java:179)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    ... 1 more
Caused by: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
    at com.android.builder.png.AaptProcess$NotifierProcessOutput.handleOutput(AaptProcess.java:463)
    at com.android.builder.png.AaptProcess$NotifierProcessOutput.err(AaptProcess.java:415)
    at com.android.builder.png.AaptProcess$ProcessOutputFacade.err(AaptProcess.java:332)
    at com.android.utils.GrabProcessOutput.run(GrabProcessOutput.java:104)

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt

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

* Get more help at https://help.gradle.org

BUILD FAILED in 37s

12 actionable tasks: 12 executed

回答by Ajith Madhu

I got the same issue when upgrading from eclipse to android studio. I solved it by upgrading build.gradle.

从 eclipse 升级到 android studio 时,我遇到了同样的问题。我通过升级 build.gradle 解决了这个问题。

first, I upgraded

首先,我升级了

 buildToolsVersion 

then changed

然后改变了

  compileSdkVersion 'your api level'
  minSdkVersion 'your api level'
  targetSdkVersion 'your api level'

also upgraded

也升级了

dependencies {
implementation 'com.android.support:appcompat-v7:'your api level''
}

this solved my issue

这解决了我的问题

回答by mihai71

My experience was this: after downgrading from targetSdkVersion 21 to 19 (because about 20 phones in my company use android 4.4), I encountered the error from the title: resource android:attr/preserveIconSpacing is private.

我的经历是这样的:从targetSdkVersion 21降级到19后(因为我公司大约有20部手机使用android 4.4),我遇到了标题的错误:resource android:attr/preserveIconSpacing is private

I managed to pass over this error this way:

我设法通过这种方式传递了这个错误:

In the error message it was written the directory with the setting, in my case it was: .gradle\caches\transforms-1\files-1.1\appcompat-v7-19.0.0.aar\4cd3ccb7957b0114d8e3c7a67ecc96ad\res\values\. I opened attr.xml file from that directory, commented the whole line stated in the message, which was:

在错误消息中,它被写入了带有设置的目录,在我的情况下是:.gradle\caches\transforms-1\files-1.1\appcompat-v7-19.0.0.aar\4cd3ccb7957b0114d8e3c7a67ecc96ad\res\values\. 我从该目录打开了 attr.xml 文件,评论了消息中所述的整行,即:

<attr name="android:preserveIconSpacing" />

Now the ugly error disappeared. I didn't believe that could solve the problem because it sounds like it was a cache directory and that could be overwritten, but it wasn't like that, it worked.

现在丑陋的错误消失了。我不相信这可以解决问题,因为它听起来像是一个缓存目录并且可以被覆盖,但事实并非如此,它起作用了。

Previously I also tried to modify the attr.xml file from the android directory, which I thought to be the solution, that is android-sdk\extras\android\support\v7\appcompat\res\values\attr.xml. But that file could not be modified, it was write-protected. I closed all Android studio, no java or any other similar app started, but no luck.

之前我也尝试修改android目录下的attr.xml文件,我认为是解决方案,即android-sdk\extras\android\support\v7\appcompat\res\values\attr.xml。但是那个文件不能被修改,它被写保护了。我关闭了所有的 Android 工作室,没有启动 Java 或任何其他类似的应用程序,但没有运气。

Previously I also tried to copy "attr.xml" from the directory android-sdk\extras\android\support\v7\appcompat\res\values\, modified the preserveIconSpacing setting and then copied it in my res/values directory. No luck.

以前,我还尝试从目录android-sdk\extras\android\support\v7\appcompat\res\values\ 中复制“attr.xml” ,修改了preserveIconSpacing 设置,然后将其复制到我的 res/values 目录中。没有运气。

UPDATE 2018-nov-05. In another installation it wasn't an "attr.xml" file that contained that string "". So I searched the whole "res" directory specified in the error and it was found/located in "values.xml" file . I commented it there. And it worked.

更新 2018 年 11 月 5 日。在另一个安装中,它不是包含字符串“”的“attr.xml”文件。所以我搜索了错误中指定的整个“res”目录,它被找到/位于“values.xml”文件中。我在那里评论过。它奏效了。

I hope this helps somebody.

我希望这对某人有帮助。

回答by Sufian

For some reason I wanted to compile my project with KitKat (API level 19) and doing so with the latest canary (Android Studio 3.3 Canary 5) was not working (I don't remember the error message but I had wasted quite some time due to that and thought it might come out as helpful to someone having the same problem).

出于某种原因,我想用 KitKat(API 级别 19)编译我的项目,并且用最新的 Canary(Android Studio 3.3 Canary 5)编译我的项目不起作用(我不记得错误消息,但我浪费了很多时间对此,并认为它可能对遇到相同问题的人有所帮助)。

I did the following things:

我做了以下几件事:

  1. open the project in Android Studio 2.3 stable,
  2. open the build.gradlefile of my project (not that of app module!) and set the plugin version to 2.2.3:

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
    
  3. replaced google()in the build.gradleof the project with (if you don't have any google()in your file):

    maven {
        url 'https://maven.google.com'
    }
    
  4. open gradle-wrapper.propertiesand set gradle version to 2.14.1 (this pageis useful when picking plugin and gradle versions which are compatible with each other):

    distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
    
  1. 在 Android Studio 2.3 stable 中打开项目,
  2. 打开我项目的build.gradle文件(不是 app 模块的!)并将插件版本设置为 2.2.3:

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
    
  3. google()在项目的build.gradle中替换为(如果您google()的文件中没有):

    maven {
        url 'https://maven.google.com'
    }
    
  4. 打开gradle-wrapper.properties并将 gradle 版本设置为 2.14.1(此页面在选择相互兼容的插件和 gradle 版本时很有用):

    distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip