I am using 'com.android.tools.build:gradle:2.2.0-alpha6' and Android Studio 2.2 Preview 6. The build runs perfectly fine on Gradle 2.1.0, but to enable instant run it asks me to update Gradle plugin.
On updating Gradle plugin, the build shows "Error:Could not find property 'assembleDebug' on project ':app'". I already tried cleaning .gradle and .idea and reloading the project, but nothing works.
Please help.
find which task is depending on assembleDebug task
changing the following did the trick for me at least:
from:
task findbugs(type: FindBugs, dependsOn: assembleDebug)
to:
task findbugs(type: FindBugs, dependsOn: "assembleDebug")
so just surrounding the task with quotes was enough.
It's from In that case, a workaround is this way:
//assembleDebug.doFirst {
// println '=============assembleDebug============='
//}
//assembleRelease.doFirst {
// println '=============assembleRelease============='
//}
//
// =======>
tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebug') {
//task.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint'
println '=============assembleDebug============='
} else if (task.name == 'assembleRelease') {
//task.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint'
println '=============assembleRelease============='
}
}
If you have no any "assemble" in your project, so check an answer from this post:
Could not get unknown property 'assemble'
Related
My project was running perfect with gradle plugin version 3.0.1 after updating to version 3.4.1 I am going through sync failure.
Previously I was using wrapper 4.10.1 which is now updated to 5.1.1.
afterEvaluate(new Action<Project>() {
#Override
void execute(Project project) {
tasks.getByName("assembleRelease").doLast {
tasks.copyReleaseBuild.execute() //error is here
tasks.copyReleaseBuildToXX.execute()
tasks.copyReleaseBuildToXXXX.execute()
}
}
copyReleaseBuild task is written something like below...
task copyReleaseBuild(type: Copy) {
def releaseDir = getProjectProperty('releaseDir')
if (releaseDir?.trim()) {
//if release folder is provided
def releaseAarFile =
getProjectProperty('sourceCodeDir') + "/android-corekit/kit/build/outputs/aar/kit-release.aar"
from releaseAarFile
into releaseDir
}
task copyReleaseBuildToXX(type: Copy) {
from "./build/outputs/aar/kit-release.aar"
into "../kitwrapper/libs"
}
task copyReleaseBuildToXXXX(type: Copy) {
from "./build/outputs/aar/kit-release.aar"
into "../kitwrapperapp/libs"
}
}
I have been trying to resolve from last two days but nothing is working as I lack knowledge of groovy.
Please check error log I am getting while building the project...
It happens because you are using an updated version of gradle (check the migration to gradle v5)
The following properties and methods of TaskInternal have been removed — use task dependencies, task rules, reusable utility methods, or the Worker API in place of executing a task directly.
execute()
executer
getValidators()
addValidator()
Now you can't call the execute method directly, but you have to use the tasks dependencies to obtain the same result.
Just define in your build.gradle:
task copyReleaseBuild {
dependsOn 'assembleRelease'
//...
}
and remove this:
afterEvaluate(new Action<Project>() {
#Override
void execute(Project project) {
tasks.getByName("assembleRelease").doLast {
tasks.copyReleaseBuild.execute() //error is here
}
}
Upgrading your build from Gradle 4.x to 5.0
The following properties and methods of TaskInternal have been removed — use task dependencies, task rules, reusable utility methods, or the Worker API in place of executing a task directly.
execute()
executer
getValidators()
addValidator()
in your case seems you have dependency between tasks: copyReleaseBuild must run after assembleRelease
so, this simple build.gradle represents this dependency:
task copyReleaseBuild {
dependsOn 'assembleRelease'
doLast {
println 'run copyReleaseBuild'
}
}
task assembleRelease {
doLast {
println 'run assembleRelease'
}
}
and the command gradle copyReleaseBuild
runs both tasks:
# gradle copyReleaseBuild
> Task :assembleRelease
run assembleRelease
> Task :copyReleaseBuild
run copyReleaseBuild
BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed
I use FindBugs for static code analysis in my Android projects. The setup is the following:
quality.gradle
plugins.apply('findbugs')
task findbugs(type: FindBugs) {
ignoreFailures = false
effort = 'max'
reportLevel = 'high' // Report only high priority problems.
classes = files("${project.projectDir}/build/intermediates/classes")
source = fileTree('src/main/java')
classpath = files()
reports {
xml.enabled = true
html.enabled = false
}
excludeFilter = rootProject.file('quality/findbugs.xml')
}
build.gradle:
subprojects {
afterEvaluate {
project.apply from: '../quality/quality.gradle'
tasks.findByName('findbugs').dependsOn('assemble')
tasks.findByName('check').dependsOn('findbugs')
}
}
But after I upgraded the Gradle Android Plugin from 3.1.3 to 3.2.0 the build started failing:
./gradlew clean build
> Task :app:findbugs FAILED
No files to be analyzed
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:findbugs'.
> Failed to run Gradle FindBugs Worker
> Process 'Gradle FindBugs Worker 6' finished with non-zero exit value 1
Downgrading to 3.1.3 makes the build pass again. I haven't found anything related in the changelog of the Gradle Android Plugin. Can anybody point me out what's wrong with the plugin or my setup?
After a short investigation, I found out that the location of Java class files has changed from build/intermediates/classes to build/intermediates/javac. The new FindBugs configuration:
task findbugs(type: FindBugs) {
...
classes = files("${project.projectDir}/build/intermediates/javac")
...
}
The strange thing that this breaking change isn't mentioned in the Android Gradle Plugin changelog, or in the Gradle changelog.
I want to run my custom task after assembleDebug task in Android Studio.My normal build.gradle is
apply plugin: 'com.android.application'
android {
...
}
dependencies {
...
}
task printName{
println 'Hello Guffy'
}
printName.shouldRunAfter(tasks.assembleDebug)
// or printName.shouldRunAfter(assembleDebug)
// or assembleDebug.shouldRunAfter(printName)
which is not compiling.The gradle error is
Error:(36, 0) Could not get unknown property 'assembleDebug' for task set
Is assembleDebug or other tasks not available to custom tasks ? Or is there any basic error I am doing ? Thanks
Suggested by Piotr Zawadzki, putting task in quotes worked .
So the code should be like
printName.shouldRunAfter("assembleDebug")
After updating Android Studio to version 2.2 and the Gradle-plugin to 2.2.0, I get following error:
"Could not get unknown property 'assembleRelease' for project ':app' of type org.gradle.api.Project."
When I change the plugin version back to 2.1.3 the code still works, but that's no long-term option for me.
My code:
apply plugin: 'com.android.application'
dependencies {
...
}
android {
...
}
...
assembleRelease.doLast {
file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
}
Hint:
project.ext.androidVersionCode is a variable defined otherwhere and contains a build number. The code in assembleRelease.doLast shall just move/rename the generated apk file.
Thank you for advices!
tangens
tasks.whenTaskAdded { task ->
if (task.name == 'assembleRelease') {
task.finalizedBy 'yourRenameTasks'
}
}
You may rewrite your task a bit and try like this:
task renameBuildTask() << {
file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
dependsOn 'assembleRelease'
}
Also you can check this question to get better understanding.
EDIT
As #tangens said in a comment:
It works when I replace the call gradle assemble by e.g. gradle renameBuildTask. Thank you! The answer contains an error. Correct would be: task renameBuildTask() << { ... }
maybe wrap code in afterEvaluate{} will be work:
afterEvaluate {
assembleRelease.doLast {
file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
}
}
gradle-2.14.1 and android gradle plugin 2.2.0
details:
Could not get unknown property 'assembleDebug' (2.2-beta)
I had the same problem after upgrading Android Studio to 2.2 and Gradle to 2.2.
I have task copyApk that needs to be run at the end of building. For brevity, let me skip what was working before, and post only what is working right now:
tasks.create(name: 'copyApk', type: Copy) {
from 'build/outputs/apk/myapp-official-release.apk'
into '.../mobile'
rename('myapp-official-release.apk', 'myapp.apk')
}
tasks.whenTaskAdded { task ->
if (task.name == 'assembleRelease') {
task.dependsOn 'copyApk'
}
}
Gradle console shows copyApk was run near the end after packageOfficialRelease, assembleOfficialRelease, right before the last task assembleRelease. "Official" is a flavor of the app.
I got the workaround from this SO post. I essentially copied the answer here for your convenience. All credits go to the author of that post.
inside buildTypes {} method, I put this code : worked like a charm
task setEnvRelease << {
ant.propertyfile(
file: "src/main/assets/build.properties") {
entry(key: "EO_WS_DEPLOY_ADDR", value: "http://PRODUCTION IP")
}
}
task setEnvDebug << {
ant.propertyfile(
file: "src/main/assets/build.properties") {
entry(key: "EO_WS_DEPLOY_ADDR", value: "http://DEBUG IP TEST")
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebug') {
task.dependsOn 'setEnvDebug'
} else if (task.name == 'assembleRelease') {
task.dependsOn 'setEnvRelease'
}
}
you can do this:
task copyApk(dependsOn: "assembleRelease") << {
file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
}
As of com.android.tools.build:gradle:1.3.0 you can run into Task with name 'testDebug' not found in project ':module'.
As in the earlier stage of the build environment it was not possible to test library modules properly using Robolectric & Java this workaround was created:
afterEvaluate { project ->
android.libraryVariants.each { variant ->
println variant.name
println tasks
tasks.getByName("test${variant.name.capitalize()}") {
dependsOn "assemble${variant.name.capitalize()}"
}
}
}
With version 1.3.0 this is broken.
They have changed the name from testDebug to testDebugUnitTest hence the code above needs to be changed to:
afterEvaluate { project ->
android.libraryVariants.each { variant ->
println variant.name
println tasks
tasks.getByName("test${variant.name.capitalize()}UnitTest") {
dependsOn "assemble${variant.name.capitalize()}"
}
}
}