Android studio 编译错误“内容不允许在序言中”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25145539/
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-08-20 09:08:55  来源:igfitidea点击:

Android studio compile error "Content is not allowed in prolog"

androidcompiler-errorsresources

提问by Never_be

I use latest Android Studio 0.8.4 (for OS X), in "res" directory I create new "database" directory and put there all files what I need and when I try to compile I receive this error.

我使用最新的 Android Studio 0.8.4(适用于 OS X),在“res”目录中创建新的“数据库”目录并将我需要的所有文件放在那里,当我尝试编译时收到此错误。

Error:Content is not allowed in prolog.
:app:mergeDebugResources FAILED
/Users/filipp/data/Android_dev/project/app/src/main/res/database/5clSubject0Book0.txt
Error:Error: Content is not allowed in prolog.
Error:Execution failed for task ':app:mergeDebugResources'.
> /Users/filipp/data/Android_dev/project/app/src/main/res/database/5clSubject0Book0.txt:0:0:   Error: Content is not allowed in prolog.
Information:BUILD FAILED

回答by CommonsWare

in "res" directory I create new "database" directory

在“res”目录中我创建了新的“数据库”目录

That is not supported. You cannot invent new resource directories.

这是不支持的。你不能发明新的资源目录。

Please put the files in res/raw/(and use via getResources().openRawResource()) or assets/(and use via getAssets().open()).

请将文件放入res/raw/(并使用 via getResources().openRawResource())或assets/(并使用 via getAssets().open())。

回答by Amjad Khan

I am having the same problem What I did is,

我有同样的问题我所做的是,

You need to clear the cache data

您需要清除缓存数据

Go to Build(Menu)--> Clean Project

转到构建(菜单)--> 清理项目

Then

然后

Go to Build(Menu)--> Rebuild Project

转到构建(菜单)--> 重建项目

Then Run Your project

然后运行你的项目

This may also help in refreshing data of android preview

这也可能有助于刷新android预览的数据

回答by DiscDev

In my case, I had accidentally entered a random character right before the beginning of my strings.xml file.

就我而言,我不小心在strings.xml 文件开头之前输入了一个随机字符。

enter image description here

在此处输入图片说明

I removed the "f" character before the xml declaration and all was well again.

我在 xml 声明之前删除了“f”字符,一切又好了。

回答by Arthur

You might want to clean caches

您可能想要清理缓存

C:\Users\<username>\.gradle\caches

回答by Prakash G Khaire

Try the following steps

尝试以下步骤

  1. Go to the Build Menu.
  2. Select the option Clean Project.
  3. Once again, go to the Build Menu.
  4. Select the option Rebuild Project.
  1. 前往Build Menu.
  2. 选择选项Clean Project
  3. 再次前往Build Menu.
  4. 选择选项Rebuild Project

It worked for me.

它对我有用。

回答by Kieron

Old question but googling the error got me here.

老问题,但谷歌搜索错误让我在这里。

This was fixed for me by deleting the (empty) "navigation" folder from res, it was left over when checking out a different branch from a repository, appears it can't be empty or it will cause this error.

这是通过从 res 中删除(空的)“导航”文件夹为我解决的,它在从存储库检出不同的分支时遗留下来,看起来它不能为空,否则会导致此错误。

回答by Taani

I faced the same error when I created assets folder inside app/src/main/res/

当我在 app/src/main/res/ 中创建资产文件夹时,我遇到了同样的错误

We shouldn't create folders anywhere at our will. To create new folders, make sure that you go to
File -> Folder and consequently ,choose one of the folders among the options displayed. This way the IDE creates the folder at appropriate locations and thus accessing them doesn't raise any errors.

我们不应该随意在任何地方创建文件夹。要创建新文件夹,请确保转到
文件 -> 文件夹,然后在显示的选项中选择文件夹之一。这样,IDE 会在适当的位置创建文件夹,因此访问它们不会引发任何错误。

回答by Gaurav Agrawal

You can only have predefined set of folder inside res folder. so you are creating database folder inside res folder which is invalid. Either put database files inside assets folder or raw folder.

您只能在 res 文件夹中拥有一组预定义的文件夹。所以你在 res 文件夹中创建了无效的数据库文件夹。将数据库文件放在 assets 文件夹或 raw 文件夹中。

回答by Elynad

Perform Build Cleanand Rebuild Projectdid not work for me.

执行Build CleanRebuild Project没有为我工作。

I had to manually delete .idea/caches, then rebuild project.

我不得不手动删除.idea/caches,然后重建项目。

回答by Tushar Varshney

I removed all of the compile statements. Then, I deleted the jar files from libs (and selected 'safe delete'). Once that was done, I dragged the jar file back into libs. Once there, I right clicked on libs selected to add it as a library. Now the gradle builds fine and everything works.

我删除了所有的编译语句。然后,我从库中删除了 jar 文件(并选择了“安全删除”)。完成后,我将 jar 文件拖回库中。在那里,我右键单击所选的库以将其添加为库。现在 gradle 构建良好,一切正常。