As part of my build script, I would like to run some Java code before the APK is packaged.
When I try to build my project, I get the error:
Error: Could not find or load main class net.bgreco.myapp.build.BuildScript
BuildScript.java
is located in app/src/main/java/net/bgreco/myapp/build/
.
The BuildScript.class
does get compiled successfully before I receive the error message above, and I can run it from the command line with no errors.
app/build.gradle
:
task runBuildScript(type: JavaExec) {
main = 'net.bgreco.myapp.build.BuildScript'
}
tasks.whenTaskAdded { theTask ->
if (theTask.name.contains('package')) {
theTask.dependsOn 'runBuildScript'
}
}