Ant rebuilding library projects every time

前端 未结 3 585
闹比i
闹比i 2021-02-10 10:09

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 20s

相关标签:
3条回答
  • 2021-02-10 10:40

    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.

    0 讨论(0)
  • 2021-02-10 10:40

    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.

    0 讨论(0)
  • 2021-02-10 10:49

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

    0 讨论(0)
提交回复
热议问题