title: How to add custom task to android gradle build for mergeJniLibFolders
body: <p>A bit of background, I have a custom android build type called "prebuilt" which is intended to be deployed to an android system image. I need custom gradle tasks to modify the assets and jniLibs folders so that these are delivered separately from the apk (e.g., my-app-prebuilt.apk, my-app-prebuilt-assets.zip, my-app-rebuilt-libs.zip). I do not want to modify debug or release buildTypes for normal deployment.</p>
  
  <p>Stripping the assets step was fairly easy once I stumbled on the right task <code>mergeAssets</code> to modify:</p>
  
  <pre><code>buildTypes {
          applicationVariants.all { variant -&gt;
              if (variant.buildType.name == 'prebuilt') {
                  variant.mergeAssets.doLast {
                      // Delete from prebuilt build type. It will be delivered in parallel.
                      delete(fileTree(dir: variant.mergeAssets.outputDir, includes: ['**/somestuff/*']))
                  }
                  // I want mergeJniLibFolders but this doesn't seem to exist?
                  variant.mergeJniLibFolders.doLast {
                      delete(fileTree(dir: variant.mergeJniLibs.outputDir, includes: ['**/*.so']))
                  }
              }
  }
  </code></pre>
  
  <p>I get an error for the mergeJniLibFolders property:</p>
  
  <blockquote>
    <p>Could not get unknown property 'mergeJniLibFolders' for object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.</p>
  </blockquote>
  
  <p>I was expecting a <code>mergeJniLibFolders</code> or <code>mergePrebuiltJniLibFolders</code> to be modifiable to perform the second step of deleting the libs. I am starting to splunk through gradle ApplicationVariantImpl.</p>
  
  <p>An aside, the <code>variant</code> object is needed to know the outputDir. For some time I was thinking I could make a <code>task stripPrebuiltAssets &lt;&lt; { dependsOn: mergePrebuiltMergeAssets, ...}</code>, but I wouldn't have the variant object. This is also rather confusing to me.</p>
  
  <p>I am feeling around in the dark and do not have a good sense of what I can "do" with the Android Plugin DSL. I have read through the reference several times and I have a decent understanding of the AppExtension and properties that can be modified, but how does this translate to the hundred tasks in the gradle tree? I seem to be missing a resource to understand this better.</p>
  
  <p>My Android Studio's poor gradle autocomplete is also frustrating. It seems to identify one autocomplete option only if I have already used it. I am using</p>
  
  <ul>
  <li>Android Studio 3.2.1</li>
  <li>Gradle 4.10.2</li>
  <li>com.android.tools.build:gradle:3.2.1</li>
  </ul>
  
  <p>Bonus question is zipping up the assets and jniLibs that I am stripping in the two rules so that it is available alongside the <code>my-app-prebuilt.apk</code>. I roughly understand I need a task of type Zip that will zip the folder <code>/build/intermediates/transforms/mergeJniLibs/prebuilt/0/lib/</code> and then delete the folder. I am also expecting <code>variant.mergeJniLibs.outputDir</code> to exist but this also seems to be missing.</p>
  
  <p>Cheers for any insight.</p>