Welcome to follow my public numberEfficient Android Development“Focuses on Android project efficiency and development experience, covering topics such as infrastructure, Kotlin Multiplatform, Gradle construction and optimization, etc. At the same time, we also talk about overseas work and life, and push the latest Podcast of” Two-part radio “.

“Build North” is a series of articles exploring Android building. It covers Gradle, Android Gradle Plugin, Kotlin Script, and other tools, as well as related architecture applications. To find the problem to solve the problem as the starting point, transfer new knowledge to improve production efficiency as the foothold.

When you upgrade the Android Gradle Plugin to 2.3.0, you find that the folder in the compile-aar build directory is mostly gone (although an AAR package or two still pops up, which is a little weird). The most relevant reason for this change is that Build Cache is enabled by default in 2.3.0, as explained here.

Our previous requirement to collect information from pestilence-aar assets of the app Module for other modules was also unable to do so. A quick Google search will find complaints, and the solution is to turn off Build Cache. This clearly does not meet our productivity needs, so I looked into the relevant source code.

Search for BuildCache and you’ll find this code in the Library-related Task:

[->PrepareLibraryTask.java]

/**
 * Returns {@code true} if the build cache should be used for the prepare-library task, and
 * {@code false} otherwise.
 */
public static boolean shouldUseBuildCache(
            boolean buildCacheEnabled, @NonNull MavenCoordinates mavenCoordinates) {
    // We use the build cache only when it is enabled *and* the Maven artifact is not a snapshot
    // version (to address http://b.android.com/228623)
    returnbuildCacheEnabled && ! mavenCoordinates.getVersion().endsWith("-SNAPSHOT");
}
Copy the code

Therefore, the first problem was solved. Some users suggested that the Cache should take into account the Maven repository’s release habit, and that the situation like SNAPSHOT, which often has multiple versions with the repository, should be ignored and collated (using the original rebele-aar).

There is no way to solve the problem from here, but since the data collection was done from Assets, is it possible to do it from RAW? After all, these are two very similar folders, but the packaging process is somewhat different.

We can see the merge of raw results are in. / build/intermediates/res/merged/release/raw, exploded – the aar does not go, so this is a compatible with all versions of a clever solution: If you also need to write information to each Library module and collect it from the app Module, merged Raw is a better staging solution at the moment and don’t rely on exploded exploded aar (unless you post all snapshots).

Welcome to comment like, and follow my public accountEfficient Android Development.