Ant rebuilding library projects every time

你说的曾经没有我的故事 提交于 2019-12-04 12:33:51

问题


I have an Android project that includes two Android Library projects.

I'm using the command ant debug to build the project and it takes around 1min and 20sec. I've counted that 17 seconds are used to compile the first android library project and 42 seconds are used to compile the second android library project.

Since these two dependency projects are rarely updated it's not necessary to compile them each time.

How can I avoid ant compiling the two Android library projects each build?


回答1:


Add dont.do.deps=1 to your local.properties (or pass this property to ant some other way)




回答2:


This is how Android Library Project is designed and suppose to work at the moment, it is always compiled indirectly along with the main application project compilation, see this official dev guide:

However, a library project differs from an standard Android application project in that you cannot compile it directly to its own .apk and run it on an Android device. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.

... ...

Development considerations

  • You cannot export a library project to a JAR file

    A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.

How can I avoid ant compiling the two Android library projects each build?

The thing you talking about is a pre-compiled jar file. There are some posts here suggest using Eclipse export function or the auto-generated jar under library project's bin directory, it may work in some simple case like the library project contains purely Java file, but will not work if the library project become more complicated which contains Android resource files. In this case, there are some dirty hack like this one which IMO cause more trouble than it solves.

Android dev team is working on it and try to change Android Library Project from source-based mechanism to compiled-code based library mechanism. more details in this blog post. I suggest waiting for the ultimate solution from official dev team.




回答3:


I had issues with slow Android compilation when I had libraries in my project and solved this by applying "--incremental" switch to dex tool. See this question on SO.



来源:https://stackoverflow.com/questions/11375635/ant-rebuilding-library-projects-every-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!