I need to copy some files to the Android App folder (data/data/...) after installing the app via Gradle. This has to be done at every debug build before the app gets started and thus I assumed I could find a gradle task that could be executed after the installation (but before the run command).
It works somewhat fine for other tasks when doing something like
tasks.whenTaskAdded { task ->
if (task.name == 'build') {
task.dependsOn taskXYZ
}
}
They then get executed before my build task is executed. However, since I need that to happen after the install process (and before the running of the app) I was hoping for something like this:
tasks.whenTaskAdded { task ->
if (task.name.startsWith('install')){
println ">>>>>>>>> " + task.name
task.finalizedBy taskXYZ
}
But sadly, this does not work.
In the build output I can see that this executed pretty much at the start.
Executing tasks: [:app:assemblePlayStoreStagingDebug] in project /Users/...
> Configure project :app
###########################
TASK XYZ WAS EXECUTED HERE!
###########################
---> installPlayStoreStagingDebug
> Task :app:preBuild UP-TO-DATE
> Task :app:prePlayStoreStagingDebugBuild
> Task :app:compilePlayStoreStagingDebugAidl UP-TO-DATE
...
> Task :app:stripPlayStoreStagingDebugDebugSymbols UP-TO-DATE
> Task :app:packagePlayStoreStagingDebug
> Task :app:assemblePlayStoreStagingDebug
BUILD SUCCESSFUL in 6s
33 actionable tasks: 6 executed, 27 up-to-date
It looks like the task did not get executed at the expected time. What I need is something like this:
- Task Build
- Task Install
- Task XYZ
- Task run App
But how can I achieve this?
Solutions like this one Android run Gradle task after app install Don't seem to work for the install task.
----- EDIT -----
I tried it the other way around and - instead of using gradle tasks - I tried to change the run configuration of AS by adding an "external tool" call in the "before launch" settings.
https://developer.android.com/studio/run/rundebugconfig#definingbefore
However, when selecting for instance a shell script there, it won't get executed (for instance I was creating a file or directory in that script so I could see whether it was executed at all). It doesn't seem to be that error=13 permission problem. So if gradle tasks are not a solution, perhaps anyone knows a solution with this option!