C# 为 Android 项目构建 Mono 时,“aapt.exe”以代码 1 退出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11440741/
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
"aapt.exe" exited with code 1 when building Mono for Android project
提问by patridge
I put together a fairly simple Mono for Android application that does nothing more than play an "AndroidResource" MP3 in a background service (copied from Greg Shackles latest Visual Studio Magazine article on Background Services in MfA). I put the code together, with my own custom MP3 file, and tried to build it, only to get this lovely error.
我为 Android 应用程序组合了一个相当简单的 Mono,它只不过是在后台服务中播放“AndroidResource”MP3(复制自Greg Shackles 最新的 Visual Studio 杂志关于 MfA 后台服务的文章)。我将代码与我自己的自定义 MP3 文件放在一起,并尝试构建它,结果却出现了这个可爱的错误。
"aapt.exe" exited with code 1
That is the only info in the error list and build output log.
这是错误列表和构建输出日志中的唯一信息。
采纳答案by patridge
Step 1: get more info
第 1 步:获取更多信息
If you run across this error, hopefully, you will also run across a post from Jonathan Pryorreplying to someone else with the same problem. The suggestion is to turn on more verbose logging from MSBuild to see if you get something useful out of those messages.
如果您遇到此错误,希望您还会遇到Jonathan Pryor的帖子,该帖子回复了有相同问题的其他人。建议是从 MSBuild 中打开更详细的日志记录,以查看是否从这些消息中获得了一些有用的信息。
In the Visual Studio Options dialog, go to "Projects and Solutions" then "Build and Run". Switch the "MSBuild project build output verbosity" from "Minimal" to "Normal" and build your project again. After doing so, I got this message which was far more helpful. Apparently, resources cannot include anything but letters, numbers, periods, and underscores ([a-z0-9_.]).
在 Visual Studio 选项对话框中,转到“项目和解决方案”,然后转到“构建和运行”。将“MSBuild project build output verbosity”从“Minimal”切换到“Normal”并再次构建你的项目。这样做之后,我收到了这条消息,这更有帮助。显然,资源只能包含字母、数字、句点和下划线 ( [a-z0-9_.]) 。


Solution
解决方案
Rename file within the required restrictions and build again.
在所需的限制内重命名文件并再次构建。
While this error message may come up for far more situations than filename restriction issues, a filename change fixed this particular issue completely.
虽然此错误消息可能出现的情况远多于文件名限制问题,但文件名更改完全解决了此特定问题。
回答by Dylan
For me it was a problem with a resource name. One of my pictures was from MonoTouch and as such its filename included an '@2x' in the filename. After removing this aapt.exe no longer complained and the solution built.
对我来说,这是资源名称的问题。我的一张照片来自 MonoTouch,因此它的文件名在文件名中包含一个“@2x”。删除此 aapt.exe 后不再抱怨并构建了解决方案。
回答by Hersker
In Mono.Android projects this error occurres when a Resources/Layout axml file has whitespaces in the name, eg. "Copy of xxxx.xaml"
在 Mono.Android 项目中,当资源/布局 axml 文件的名称中包含空格时,会发生此错误,例如。“xxxx.xaml 的副本”
回答by StefanoM5
In Mono.Android projects this error can happen when a Resources/Drawable file name has - in the name, eg: "File-Name.png try with underscore: "File_Name.png"
在 Mono.Android 项目中,当资源/可绘制文件名包含 - 时,可能会发生此错误,例如:“File-Name.png try with underscore:”File_Name.png”
回答by Ruwan Jayalath
Check your images/png(s) on Drawable folder. It gave me an error because of a png image, once it is excluded from project. Works fine...
检查 Drawable 文件夹中的图像/png(s)。一旦从项目中排除了 png 图像,它就会给我一个错误。工作正常...
回答by Joel
Similar solution for me, I needed to remove the dashes ('-') from my PNG filenames in the resources folder
对我来说类似的解决方案,我需要从资源文件夹中的 PNG 文件名中删除破折号 ('-')
回答by Tiago S
Follow the steps below to identify the problem:
请按照以下步骤确定问题:
1 - In Visual Studio: Tools> Options> Projects and solutions> Build and Run.
1 - 在 Visual Studio 中:工具>选项>项目和解决方案>构建和运行。
1.1 - In the dropdown: MSBuild project build output verbosity:> Diagnostic.
1.1 - 在下拉列表中:MSBuild 项目构建输出详细信息:> 诊断。
1.2 - Close the dialog box.
1.2 - 关闭对话框。
2 - View> Output (Ctrl + W, O).
2 - 查看>输出(Ctrl + W,O)。
3 - Run the build or rebuild.
3 - 运行构建或重建。
In the output find this line:
在输出中找到这一行:
C: \ Program Files (x86) \ MSBuild \ Xamarin \ Android \ Xamarin.Android.Common.targets (1665.3): error MSB6006" aapt.exe "exited with code 1
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets (1665.3): error MSB6006" aapt.exe "exited with code 1
What is just above this error is what caused the error.
这个错误的正上方是导致错误的原因。
回答by Mahesh Iyer
Yes, Remember to not have:
是的,记住不要有:
- Resources, Images, Assets, Layout axml beginning with mumbers
- To check your file names with spaces. (I had this issue. One of my layouts had an ending space just before the extension ".axml")
- To check if any of your images, resources, files, layouts or others have any hyphen (-). They are not supposed to be there.
- 资源、图像、资产、布局 axml 以 mumbers 开头
- 用空格检查文件名。(我遇到了这个问题。我的一个布局在扩展名“.axml”之前有一个结束空间)
- 检查您的任何图像、资源、文件、布局或其他内容是否有任何连字符 (-)。他们不应该在那里。
回答by Victor
I resolved it by removing portable library that contains the business logic from the android and then rebuild it separately. After rebuilding, clean your android project and add reference again to your portable class library. Finally build the android project
我通过从android中删除包含业务逻辑的可移植库然后单独重建它来解决它。重建后,清理您的 android 项目并再次向您的可移植类库添加引用。最后构建android项目

