preface

Apt /annotationProcessor and Provided compile only without input to APK. What’s the difference between them? So I’m going to share with you what I know.

The body of the

Compile relation apt/annotationProcessor

Dependent libraries are only executed at compile time, but are not ultimately packaged into APK. From the previous demo, to summarize:

The code in the compiled library does not make sense to use directly, nor does it provide open API calls. The ultimate goal is to get files generated in the compiled library for us to call.

For example, in demo, the relationship between APP and IO-Compiler is compilation. When APP is running, the MainActivity generated by Io-Compiler compilation is required. ViewInject file, independent of the IO – Compiler.

Let’s do an analogy:

The cast

Xiaoming: Act the app. Vending machine: Act as a compilation library. Nutrition Express: Files generated by the compilation library.

Xiao Ming is standing in front of the vending machine and says to it, “I feel my body is being emptied. Give me a bottle of nutrition express!” Then the vending machine suddenly leisurely pop up a bottle of nutrition fast line, and then Xiaoming walked.

To put it simply, it is to use the compiled library to achieve the purpose, the purpose is achieved and it is discarded, we just want the results of the compiled library. That’s pretty much what it means. The concept is in place.

Provided

Provided, while also executed at compile time and ultimately not packaged into APK, is fundamentally different from APT /annotationProcessor.

The general application scenario is as follows:

A, B, and C are libraries. A depends on C, and B depends on C. The App needs to use both A and B, so A (or B) can change its dependency with C to Provided

The Library A actually needs C, but it knows that B also has A C, so it’s unnecessary to bring another one. When the app starts running, A can get C from B, which means that both of them share the SAME C. So just before he joins up with B, let’s say he has C. If you run without C, you’re going to crash.

Here’s another metaphor:

Xiaoming: Play app Xiaogang: Play Library (A) Xiaomao: Play Library (B)

Story: Spring to Xiaoming lonely, to Xiaogang and xiaomao call: tonight night sexy, we go to the big health care, bring your membership card, I treat! Xiaogang: I have a membership card of XXX, which is available to all members and not allowed to enter. It is very safe. Xiaomao and I can only take one card. Xiaomao: No problem! Why don’t you bring your membership card? I’ll pick you up.

Ending 1 Xiaogang did not forget to bring membership card, everything went well.

Ending 2 xiaogang forget to bring membership card, 3 people because of the plan to be disappointed.

If you have a little problem, don’t worry about it. It’s the idea, you know.

To sum up, a Provided is an indirectly dependent Library that must be run to ensure that this Library exists, or else it will crash to avoid relying on duplicate resources.

conclusion

Here is the end, I do not know if you have a deeper understanding of their difference, if there is any question on the message, we will discuss again.