Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant rebuilding library projects every time

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?

like image 869
Giorgio Avatar asked Jul 07 '12 14:07

Giorgio


2 Answers

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

like image 85
rkapl Avatar answered Sep 27 '22 22:09

rkapl


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.

like image 31
yorkw Avatar answered Sep 27 '22 22:09

yorkw