9

I am facing issue with Android Studio 3, gradle android plugin 3 with build target 27 and support lib 27.0.0

Error:Execution failed for task ':module:mockableAndroidJar'.
> Output file [[...]/build/generated/mockable-android-27.v3.jar] already exists.

I have to clean or manually delete all mockable-android jars from the generated folder time to time. So this means instead of getting better build times, I have to clean the project most of the times.

Gaurav Vashisth
  • 7,547
  • 8
  • 35
  • 56

5 Answers5

3

Simply cleanup the existing jar before running the task again. Running cleandoes work, but it's a little intense in my opinion. Instead, make the android-generated task depend on a very specific cleanup task:

task cleanAndroidMock(type: Delete) {
    description = 'Deletes the mockable Android jar'

    delete fileTree("${project.buildDir}/generated") {
        include 'mockable-android*.jar'
    }
}

project.afterEvaluate {
    tasks['mockableAndroidJar'].dependsOn cleanAndroidMock
}
johnmartel
  • 673
  • 6
  • 19
  • This worked for me! Not sure why the task doesn't do it in the first place, if it complains when the file is already there. – fast3r Jun 18 '18 at 09:38
3

I had this issue. Although, with API 28 platform tools. I deleted from the path and reinstalled, which worked for me.

1

I have this issue as well as I'm using a modified android.jar (which has all the hidden API revealed). I don't use the unit testing and there's no apparent way to disable it in Android Studio 2.2.2, so I found a workaround for this problem:

Go to File -> Settings -> Build, Execution, Deployment -> Compiler Add to "Command-line Options": -x :app:prepareReleaseUnitTestDependencies -x :app:mockableAndroidJar -x :app:compileReleaseUnitTestSources Press "OK" and try to Rebuild Project again. Now the unit testing compilation tasks will always be skipped and no errors will be thrown.

Nawrez
  • 3,314
  • 8
  • 28
  • 42
  • 1
    Using Android Studio 3.2, an unhidden API android.jar, I come across this too. `Could not resolve all files for configuration ':app:androidApis'.` `Failed to transform file 'android.jar' to match attributes {artifactType=android-mockable-jar, returnDefaultValues=false} using transform MockableJarTransform` – Weekend Sep 27 '18 at 12:40
  • @Weekend did you found any solution for this error message? I'm updating Android Studio to 3.2 too, and breaking my balls with the same error... :( – Joan Casadellà Oct 18 '18 at 18:06
  • 1
    @jcasadellaoller I change to AOSP android.jar, Gradle sync the project, and wait for the indexing completed. After that, change back to custom android.jar, and the project compiles. I hope this also works for you. – Weekend Oct 19 '18 at 02:12
  • 1
    Thanks for your response! Finally, we roll back the version of the com.android.tools.build:gradle: from 3.2.1 to 3.1.1. The build synck works correctly now... We will wait for newer versions and try it again! – Joan Casadellà Oct 19 '18 at 14:57
0

Try going to menu: Build -> Clean Project.
Or you can try menu: Files -> Invalidade Caches/Restart
Both worked for me!

0

Easiest solution is to navigate to the given path [[...]/build/generated/mockable-android-27.v3.jar] and simply remove the file mockable-android-27.v3.jar.Go back to android studio and build again.

Saurabh Padwekar
  • 3,888
  • 1
  • 31
  • 37