Android Build failure : Could not get unknown property 'assembleDebug' for project

701 views Asked by At

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.

2

There are 2 answers

3
Sagar On

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')
}
0
soolaugust On

base on Android Studio 2020.3.1, you can use follow codes

afterEvaluate {
    project.tasks.findByName('preDebugBuild').dependsOn(copyJarToLib)
}