title: Gradle: How to run custom task after an Android Library is built?
body: <p>I have an Android Library, it's generating a debug.aar and a release.aar, I need to copy the release.aar to another folder as a reference to other part of the project.</p>
  
  <p>What I've done now is in this Android Library build.gradle I defined a task:</p>
  
  <pre><code>task copyAARToCommonLibs(type: Copy) {
      from('../build/outputs/aar') {
          include '*-release.arr'
      }
      into '../SomeSampleApps/libs'
  }
  </code></pre>
  
  <p>I'm trying to run this task after the arr is generated, which I assume is assembleRelease stage, so I tried do this in this build.gradle</p>
  
  <pre><code>assembleRelease.doLast{
     copyAARToCommonLibs
  }
  </code></pre>
  
  <p>I build the overall project using</p>
  
  <pre><code> gradle build
  </code></pre>
  
  <p>But this task is running at the very beginning of the whole process.</p>
  
  <p>I also tried this:</p>
  
  <pre><code> applicationVariants.all { variant -&gt;
       variant.assemble.doLast {
           copyAARToCommonLibs
       }
   }
  </code></pre>
  
  <p>inside android{} property(I guess that's what it's called?)
  Running gradle build, got this error: Could not find property 'applicationVariants' </p>
  
  <p>I then came across this snippet:</p>
  
  <pre><code>tasks.withType(JavaCompile) { compileTask -&gt; compileTask.dependsOn copyAARToCommonLibs }
  </code></pre>
  
  <p>But it seems this makes the task to run after compiling, I don't know exactly how to modify this to run after assemble.</p>
  
  <p>Could someone please correct me where I did wrong and how can I get this copy task work after the .arr file is generated?</p>