0

I need to create Jar and copy to lib folder, which is done in following task :

task copyJarToLib(type: Copy, dependsOn: 'createJar') {
    from "build/libs/lib1.jar"
    from "build/libs/lib2.jar"
    into "../App/libs/"
}

I have to execute this after apk generation. So, I am calling following instruction at the end of the module-app build.gradle :

assembleDebug.finalizedBy(copyJarToLib)

Issue is observed after upgrading the gradle plugin to 3.1.0 and gradle to 4.4. Same implementation is working fine with gradle 2.3.

Vinodh
  • 1,069
  • 2
  • 10
  • 22

2 Answers2

0

If you want to execute something at the end of build, you can do it as follows:

gradle.buildFinished {

    copy {
        from "build/libs/lib1.jar"
        from "build/libs/lib2.jar"
        into "../App/libs/"
    }
}

If you want to execute task before apk is built the you can:

afterEvaluate {
    project.tasks.findByName('preDebugBuild').dependsOn(':<module>:copyJarToLib')
}
Sagar
  • 23,903
  • 4
  • 62
  • 62
0

base on Android Studio 2020.3.1, you can use follow codes

afterEvaluate {
    project.tasks.findByName('preDebugBuild').dependsOn(copyJarToLib)
}
soolaugust
  • 245
  • 2
  • 10