Basically I have 4 tasks that I need to run sequentially, but I cannot make them do so, I have to run it one by one on the command line as so:
gradle :drmdexsecondary:compileReleaseJava --info --debug --stacktrace gradle :drmdexsecondary:dexClasses --info --debug --stacktrace gradle :drmdexsecondary:jar --info --debug --stacktrace
Here's my build.gradle
:
evaluationDependsOnChildren(); task dexClasses( type:Exec ) { // compileJava.execute() String cmdExt = Os.isFamily(Os.FAMILY_WINDOWS) ? '.bat' : '' println("${buildDir}") println("${androidSdkDir}\\build-tools\\${buildToolsVersion}\\dx${cmdExt} --dex --output=${buildDir}\\classes\\classes.dex ${buildDir}\\classes\\release") commandLine "cmd", "/c", "${androidSdkDir}\\build-tools\\${buildToolsVersion}\\dx${cmdExt} --dex --output=${buildDir}\\classes\\classes.dex ${buildDir}\\classes\\release" } task jar(type: Jar) { from ("${buildDir}\\classes\\classes.dex") }
My problem is this:
dependsOn
keyword doesn't work... it just get ignored without any log messagetaskname.execute()
function doesn't work... it just get ignored without any log messagecompileReleaseJava
is not recognized inside build.gradle with this particular error: Could not find property 'compileJava' on task ':drmdexsecondary:dexClasses'.
Would anyone please help?
I've consulted and copy paste from the documentation but none of them seems work. I've even tried to re-install Gradle... there is so few sample codes there and although I understand the concept, it seems so difficult to translate my intention into working Gradle code, so if there is any good resources to help, it will be very appreciated as well.
you should use dependsOn key wordsand then move apk File to my Project/apkFile folder . and execute success. Show activity on this post. You can create a task of type GradleBuild and define the tasks inside of that task.
Task declaration is declarative not imperative. So a task can depend on another task but they cannot execute another task.
You should read about gradle tasks and more about tasks. You want to depend on things rather then invoke things.
Also I think you should read about, and use the gradle android plugin.
To your original question, when you define a task the code between the braces is run at configuration time. A task's actions are run when the task is executed and must be added to the task's action list. This is done by using the task's doFirst, doLast or the << operator.
Here is an example from the gradle documentation.
task taskX << { println 'taskX' } task taskY << { println 'taskY' } task taskZ << { println 'taskZ' } taskX.dependsOn taskY taskY.dependsOn taskZ taskZ.shouldRunAfter taskX
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With