Android studio compile error “Content is not allow

2019-01-07 00:07发布

问题:

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.

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

回答1:

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

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()).



回答2:

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



回答3:

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

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



回答4:

You might want to clean caches

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


回答5:

I faced the same error when I created assets folder inside 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.



回答6:

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.



回答7:

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.



回答8:

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.

It worked for me.



回答9:

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.