Gradle Android - Override Standard Tasks

I am trying to customize the behavior of my Gradle build for Android Wear.

I manually bind my wear apk in the processed apk (because I could not do it automatically).

This means that if I want to create a new version of the processed apk, I need to manually create my wear apk, copy / drive out the generated apk insinde my res / raw of the processed project, and then build a new processed APK.

I want all this to be automated.

So, I need to do the following:

  • Launch application: collect Undo from cmd line
  • Gradle wear first: assembleRelease
  • At the end of Gradle, take apk from wear/output/apk/wear-apk.apk and copy it to app/src/main/res/raw
  • Then Gradle can process the application: assembleRelease

I do not find how to start a task (wear: assembleRelease) from another task.

Any help is appreciated!

+5
source share
1 answer

I found a solution that may not be optimal, but it works for what I need.

In my processed application, I must first say that the assembly of Relay depends on my wear and tear: assembleRelease:

application / build.gradle

 project.afterEvaluate { preReleaseBuild.dependsOn(':wear:assembleRelease') } 

preReleaseBuild is one of the first build tasks, but this task is created dynamically, so you need to wrap it after evaluating the project.

Then, in my wear of build.gradle , I have to specify a copy at the end of the assembly:

clothes / build.gradle

 assembleRelease << { println "Copying the Wear APK" copy { from 'build/outputs/apk' into '../app/src/main/assets' include '**/wear-release.apk' } } 

Only with the thesis modifications did I manage to explain the workflow in question.

This can be improved because it only works to build the release, but this is a good first step.

Do not forget to comment on this decision.

+4
source

Source: https://habr.com/ru/post/1203401/


All Articles