Android Gradle fails to build after clean (depends

2019-09-16 05:16发布

问题:

I have an Android library project (projA) that depends on another library project (projB). I also have an internal Maven server (Archiva). projA contains these lines:

dependencies {
    maven { url 'http://company.com/internal/repository' }
    compile 'com.company:projB:2.0.7@aar'
    ...
}

projB is an AAR that was built with the Android library plugin, published to the company.com Archiva server, and it contains native code. Extracting the AAR shows the .so files exist where they should be, and the wrapper JAR file exists as well. If I run: ./gradlew clean build the build fails with unresolved symbols. However, if I run

./gradlew clean build
./gradlew build

then the second build will succeed!

This is a problem, for example, on build servers that always use clean, or get a fresh copy from source control.

Why is this happening, and how do I fix it?

回答1:

The reason this happened was because the dependency line changed, and was no longer right. I cannot figure out why it would work after one build, but not after a clean. The error message isn't clear! Even though the artifact didn't exist according to the dependency declaration, it would pass through that build step and attempt to compile.

In the end, fixing the dependency fixed this issue.

The artifact is named like this:

com.company:artifact:1.2.0.0.+@aar

That artifact exists. However, someone mistakenly changed it to:

com.company:artifact:1.2.0.0.0.+@aar

That does not exist. I had a copy of this artifact in my local ~/.m2 that fits the first, but not the second.

So, strangely, the dependency resolution had a false positive, and then the build would fail. To make matters worse, the second build (without a clean) would succeed.