Building Android app using ANT, java resource files not in final apk?
I use a Java library that has a .xml file embedded, and uses this in the code u开发者_如何转开发sing
Library.class.getResourceAsStream("file.xml")
.
When I build with eclipse
, everything goes fine. When I build with ant
(without proguard), the resource can't be found when running the app.
After some searching it turns out that the .xml file didn't got added to the bin/classes folder. So I added a copy action after the javac
command in the build.xml
file.
<copy todir="${out.classes.absolute.dir}">
<fileset dir="${lib_src}/src" includes="**/*.xml" />
</copy>
This works, in the sense that the xml files are now present in the classes
folder. However, they do not get included in the final apk package.
What is going wrong here? Which build-action do I need to modify?
Look at your /tools/ant/main_rules.xml file. This is the main build file that Android uses for its Ant builds. According to this, you should have your library files in a folder called "libs".
In any case it is a good idea for you to go through that xml file. It will explain in detail, what happens when you do commandline Ant builds.
I solved this issue by making the library android-only, not generic java. I added the xml file in the resources
dir, I think it was in the raw
dir or the xml
dir. Then I used the standard android way to get those resources.
精彩评论