Task 'assembleDebug' not found in root project

9,011 views
Skip to first unread message

jack

unread,
Jun 19, 2018, 12:35:40 PM6/19/18
to Jenkins Users
It has bugged me for a week now and still have no clue what could possibly be wrong with it... everytime I try to build in jenkins I get the following error:

[Gradle] - Launching build.
[myProjectName] $ cmd.exe /C "C:\Jenkins\workspace\myProjectName\platforms\android\gradlew.bat assembleDebug && exit %%ERRORLEVEL%%"
FAILURE: Build failed with an exception. * What went wrong: Task '
assembleDebug' not found in root project 'myProjectName'.

however when I build in Android Studio or run gradlew build assembleDebug / gradlew build assembleRelease or gradlew build clean in Windows cmd or Linux terminal, no error occured, build successful. This is a project that the devs handed to me, waiting for me to automate the build in jenkins, but they seem have made a lot of important changes in the default cordova project structure, because jenkins can perfectly build a fresh cordova project that I created, but after 5 days I tried everything I can but still got no luck in understanding what is wrong with this project (since every time I change a thing in their gradle I got a new error and jenkins still doesn't want to admit there's tasks defined in gradle... which is very annoying)...

I will give all build files in below. if anybody can spot anything... that would be fantastic and appreciated, thanks alot...

the build.gradle in Android folder is (in the computeBuildTargetName() my tasks are well defined... so why does jenkins can't find them?):
apply plugin: 'com.android.application'

buildscript {
repositories {
mavenCentral()
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.2' //if i update it to 3.0.0 i will get a unable to merge dex error and cannot seem to resolve that so i left it
}
// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
}

// Allow plugins to declare Maven dependencies via build-extras.gradle.
repositories {
mavenCentral()
google()
jcenter() //I added this line all over build files otherwise it throws me a sdk-not-found error which is absurd too
}

task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}

// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
ext {
apply from: 'CordovaLib/cordova.gradle'
// The value for android.compileSdkVersion.
if (!project.hasProperty('cdvCompileSdkVersion')) {
cdvCompileSdkVersion = null;
}
// The value for android.buildToolsVersion.
if (!project.hasProperty('cdvBuildToolsVersion')) {
cdvBuildToolsVersion = null;
}
// Sets the versionCode to the given value.
if (!project.hasProperty('cdvVersionCode')) {
cdvVersionCode = null
}
// Sets the minSdkVersion to the given value.
if (!project.hasProperty('cdvMinSdkVersion')) {
cdvMinSdkVersion = null
}
// Whether to build architecture-specific APKs.
if (!project.hasProperty('cdvBuildMultipleApks')) {
cdvBuildMultipleApks = null
}
// .properties files to use for release signing.
if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
cdvReleaseSigningPropertiesFile = null
}
// .properties files to use for debug signing.
if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
cdvDebugSigningPropertiesFile = null
}
// Set by build.js script.
if (!project.hasProperty('cdvBuildArch')) {
cdvBuildArch = null
}

// Plugin gradle extensions can append to this to have code run at the end.
cdvPluginPostBuildExtras = []
}

def hasBuildExtras = file('build-extras.gradle').exists()
if (hasBuildExtras) {
apply from: 'build-extras.gradle'
}

// Set property defaults after extension .gradle files.
if (ext.cdvCompileSdkVersion == null) {
ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
}
if (ext.cdvBuildToolsVersion == null) {
ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
}
if (ext.cdvDebugSigningPropertiesFile == null && file('debug-signing.properties').exists()) {
ext.cdvDebugSigningPropertiesFile = 'debug-signing.properties'
}
if (ext.cdvReleaseSigningPropertiesFile == null && file('release-signing.properties').exists()) {
ext.cdvReleaseSigningPropertiesFile = 'release-signing.properties'
}

// Cast to appropriate types.
ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? null : Integer.parseInt('' + cdvMinSdkVersion)
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)

def computeBuildTargetName(debugBuild) {
def ret = 'assemble'
if (cdvBuildMultipleApks && cdvBuildArch) {
def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1);
}
return ret + (debugBuild ? 'Debug' : 'Release')
}

// Make cdvBuild a task that depends on the debug/arch-sepecific task.
task cdvBuildDebug
cdvBuildDebug.dependsOn {
return computeBuildTargetName(true)
}

task cdvBuildRelease
cdvBuildRelease.dependsOn {
return computeBuildTargetName(false)
}

task cdvPrintProps << {
println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
println('cdvVersionCode=' + cdvVersionCode)
println('cdvMinSdkVersion=' + cdvMinSdkVersion)
println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
println('cdvBuildArch=' + cdvBuildArch)
println('computedVersionCode=' + android.defaultConfig.versionCode)
android.productFlavors.each { flavor ->
println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
}
}

android {

lintOptions {
abortOnError false
}

packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}

defaultConfig {
targetSdkVersion 26
multiDexEnabled true
versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")

if (cdvMinSdkVersion != null) {
minSdkVersion 21
}
}

compileSdkVersion 26
buildToolsVersion "26.0.2"


if (Boolean.valueOf(cdvBuildMultipleApks)) {
productFlavors {
armv7 {
versionCode cdvVersionCode ?: defaultConfig.versionCode + 2
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
versionCode cdvVersionCode ?: defaultConfig.versionCode + 4
ndk {
abiFilters "x86", ""
}
}
all {
ndk {
abiFilters "all", ""
}
}
}
} else if (!cdvVersionCode) {
def minSdkVersion = cdvMinSdkVersion ?: privateHelpers.extractIntFromManifest("minSdkVersion")
// Vary versionCode by the two most common API levels:
// 14 is ICS, which is the lowest API level for many apps.
// 20 is Lollipop, which is the lowest API level for the updatable system webview.
if (minSdkVersion >= 20) {
defaultConfig.versionCode += 9
} else if (minSdkVersion >= 14) {
defaultConfig.versionCode += 8
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6 //will have a Jack is needed to support java 8 error if I update it to 1_8
}

if (cdvReleaseSigningPropertiesFile) {
signingConfigs {
release {
// These must be set or Gradle will complain (even if they are overridden).
keyAlias = ""
keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph.
storeFile = null
storePassword = "__unset"
}
}
buildTypes { //many lines here are commented because I was having a keystore error but the task-not-found error appeared before this so the pb doesn't come from here
release {
// signingConfig signingConfigs.release
}
}
// addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
}
if (cdvDebugSigningPropertiesFile) {
// addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
}
}

dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(path: 'CordovaLib')
}

def promptForReleaseKeyPassword() {
if (!cdvReleaseSigningPropertiesFile) {
return;
}
if ('__unset'.equals(android.signingConfigs.release.storePassword)) {
android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ')
}
if ('__unset'.equals(android.signingConfigs.release.keyPassword)) {
android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: ');
}
}

gradle.taskGraph.whenReady { taskGraph ->
taskGraph.getAllTasks().each() { task ->
if (task.name == 'validateReleaseSigning') {
// promptForReleaseKeyPassword()
}
}
}

def addSigningProps(propsFilePath, signingConfig) {
def propsFile = file(propsFilePath)
def props = new Properties()
propsFile.withReader { reader ->
props.load(reader)
}

def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))
if (!storeFile.isAbsolute()) {
storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())
}
if (!storeFile.exists()) {
throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath())
}
signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')
signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))
signingConfig.storeFile = storeFile
signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
def storeType = props.get('storeType', props.get('key.store.type', ''))
if (!storeType) {
def filename = storeFile.getName().toLowerCase();
if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
storeType = 'pkcs12'
} else {
storeType = signingConfig.storeType // "jks"
}
}
signingConfig.storeType = storeType
}

for (def func : cdvPluginPostBuildExtras) {
func()
}

// This can be defined within build-extras.gradle as:
// ext.postBuildExtras = { ... code here ... }
if (hasProperty('postBuildExtras')) {
postBuildExtras()
}

the build-extra.gradle in Android folder:

ext.postBuildExtras = {
android.buildTypes.debug.applicationIdSuffix = '.debug'
}
ext.cdvMinSdkVersion = 16

dependencies {

compile(name:'pdftron', ext:'aar')
compile(name:'pagecropper', ext:'aar')
compile(name:'floatingactionbutton', ext:'aar')
compile(name:'tools', ext:'aar')

// noinspection GradleDependency
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:support-v4:27.1.1'
compile 'com.android.support:support-annotations:27.1.1'
compile 'com.android.support:recyclerview-v7:27.1.1'
compile 'com.android.support:design:27.1.1'
compile 'com.android.support.constraint:constraint-layout:1.1.0'

}

allprojects {
repositories {
jcenter()
flatDir {
dirs "libs"
}
}
}


android{
lintOptions {
checkReleaseBuilds false
abortOnError false
}

packagingOptions{
pickFirst 'lib/**'
pickFirst 'lib/*'
pickFirst 'lib'

}
}


the build.gradle in cordova folder is:
buildscript {
repositories {
mavenCentral()
jcenter()
}

// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
if (gradle.gradleVersion >= "2.2") {
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0+'
}
} else if (gradle.gradleVersion >= "2.1") {
dependencies {
classpath 'com.android.tools.build:gradle:0.14.0+'
}
} else {
dependencies {
classpath 'com.android.tools.build:gradle:0.12.0+'
}
}
}

apply plugin: 'com.android.library'

android {

lintOptions {
abortOnError false
}

compileSdkVersion 26
buildToolsVersion cdvBuildToolsVersion
publishNonDefault true

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}



and there is no app folder in this project. They seem have removed all the content of default app folder in the Android folder directly and merged the :app level build.gradle content into Android (root?) level build.gradle.

Victor Martinez

unread,
Jun 22, 2018, 5:13:54 AM6/22/18
to Jenkins Users
Hey,

It seems the gradle tasks which work perfectly fine are not matching with the one you run in jenkins (gradlew assembleDebug) based on the console output and your comment. Did you try to run gradlew build assembleDebug in Jenkins? Besides that, as an Idea, you could try to run a first step to list all the gradle tasks which are available for that project, something like 'gradlew tasks --all' should help you to list those tasks before running the build assembleDebug ones.

Cheers

jack

unread,
Jun 22, 2018, 5:26:56 AM6/22/18
to jenkins...@googlegroups.com
thank u for ur reply...

actually the next day I did perform a "tasks --all" in Jenkins and indeed it can't find any android or build tasks but only build steps and help tasks...

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/wtK9KC_1Gfo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/cd957ad8-93f5-43c4-b35f-5023999ace1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Martinez

unread,
Jun 22, 2018, 6:18:53 AM6/22/18
to Jenkins Users
I'd rather suggest to reproduce the same steps as the jenkins job/pipeline but using the same jenkins node:
- Create workspace with the SCM synced
- Run the gradle in the right folder 

It looks like a kind of environmental issue with the android installation in that particular jenkins node:

Cheers

jack

unread,
Jun 22, 2018, 6:33:01 AM6/22/18
to jenkins...@googlegroups.com
thank u for ur kind suggestions, will try that out !

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/wtK9KC_1Gfo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages