问题
Is there any way to exclude certain files under the /res folder from being processed by the Android builder?
I have several Android projects, which I build using Eclipse. I uploaded these projects in our version-control system. The problem is, the version-control adds some "project.pj" file to every folder.
Because of these project.pj files, my projects won't build in Eclipse anymore. I get errors because the builder tries to process these files under /res. I know I can exclude these files for the /src and /gen folders, but how do I exclude them for the /res (and /assets) folders?
回答1:
aapt
is the program that processes the files under res/. There's no way to tell it to ignore certain files. So, short answer: you can't. Your VCS is poorly suited to Android projects. Have you heard of git?
That said, your build system can be extended to move these unwanted files out of the way, run aapt, and then move them right back. As you're using Eclipse, accomplishing this means hacking its Android plugin to add these additional steps. Or perhaps writing your own plugin that performs these steps around a call to the Android plugin -- I've never hacked on Eclipse myself, and wouldn't want to. To have any other build system (e.g. using maven, or ant, or make, or scripts) do this is as simple as understanding how that system does anything. Eclipse is just way more involved. As a final option, you can write your own scripts in the project directory that move these .pj files around, and run these scripts yourself at appropriate times, without getting any help from Eclipse.
回答2:
If you prefix any file name with a period (.
) it'll be hidden from Eclipse and not included in your build.
If you're on a computer running Windows, you'll still be able to see them without issue in the Explorer. If you're on a Mac, you'll need to make sure that hidden files are being revealed if you ever want to find the file again.
回答3:
actually, there are a couple of ways to get aapt
to ignore such resources.
one such way is with the --ignore-assets to command-line invocation, if you can affect that (perhaps in build.xml if used).
you can also use aapt.ignore.assets=
in your ant.properties, if you have that.
回答4:
Use ant to control build, compile process.
来源:https://stackoverflow.com/questions/9289232/how-to-exclude-files-in-res-folder-of-an-android-eclipse-project