Ant rebuilding library projects every time

前端 未结 3 2084
不知归路
不知归路 2021-02-10 10:22

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:39

    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.

提交回复
热议问题