14

I have an Android app whose build fails when I run the following command: ./gradlew clean build -Pbuild=dev --stacktrace

Here is the error I receive:

> Task :app:lint FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':app:lint'.
> No value has been specified for property 'lintClassPath'.

App module build.gradle file:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'io.fabric'

apply plugin: "androidx.navigation.safeargs"

// For Epoxy
kapt {
    correctErrorTypes = true
}

android {
    kotlinOptions {
        jvmTarget = '1.6'
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "..."
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 8
        versionName "0.4"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        debug {
            if (project.hasProperty('ApiKey')) {
                buildConfigField('String', 'API_KEY', ApiKey)
            } else {
                buildConfigField('String', 'API_KEY', "\"mock-key\"")
            }
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (project.hasProperty('ApiKey')) {
                buildConfigField('String', 'API_KEY', ApiKey)
            } else {
                buildConfigField('String', 'API_KEY', "\"mock-key\"")
            }
        }

    }

    def build_param = "${build}"

    if (build_param != "dev") {
        //exclude production build
        android.variantFilter { variant ->
            if (variant.buildType.name == 'dev') {
                variant.setIgnore(true)
            }
        }
    } else {
        //exclude all except production build
        android.variantFilter { variant ->
            if (variant.buildType.name != 'dev') {
                variant.setIgnore(true)
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    androidExtensions {
        experimental = true
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

    // Android
    def lifecycle_version = "2.0.0"
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    implementation 'com.google.android.material:material:1.0.0'
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    implementation 'androidx.core:core-ktx:1.0.1'
    implementation 'androidx.preference:preference:1.0.0'
    implementation 'androidx.legacy:legacy-preference-v14:1.0.0'

    def room_version = "2.1.0-alpha04"
    implementation "androidx.room:room-runtime:$room_version"
    implementation "androidx.room:room-rxjava2:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    def nav_version = "1.0.0-rc02"
    implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
    implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"

    // Networking
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
    implementation 'com.squareup.okhttp3:okhttp:3.13.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.13.1'
    implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
    implementation 'com.squareup.moshi:moshi-adapters:1.8.0'
    // DI
    def koin_version = "1.0.2"
    implementation "org.koin:koin-android:$koin_version"
    implementation "org.koin:koin-androidx-scope:$koin_version"
    implementation "org.koin:koin-androidx-viewmodel:$koin_version"
    // Rx
    implementation 'io.reactivex.rxjava2:rxjava:2.2.7'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
    implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.0'
    // Image Loading
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    kapt 'com.github.bumptech.glide:compiler:4.8.0'
    // Tests
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:2.24.5'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    // UI
    implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:9.0.1'
    implementation 'com.airbnb.android:epoxy:3.2.0'
    kapt 'com.airbnb.android:epoxy-processor:3.2.0'
    implementation 'com.github.VladimirWrites:Lemniscate:1.4.4'
    // Firebase
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
}

apply plugin: 'com.google.gms.google-services'

Project level build.gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.21'
    repositories {
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'
        classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-rc02"
        classpath 'io.fabric.tools:gradle:1.27.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
        }
        maven {
            url 'https://jitpack.io'
        }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I am not sure how to fix this. Downgrading the Android Gradle plugin does not solve the issue, and there are no issues related to this anywhere on Github or Stackoverflow.

Does anyone have any idea how to fix this?

harold_admin
  • 1,117
  • 2
  • 10
  • 20

5 Answers5

17

In my case this error was triggered because ANDROID_HOME environment variable wasn't set

dorintufar
  • 660
  • 9
  • 22
  • 4
    Great, it worked !! Additional information for people using Jenkins - Set ANDROID_HOME as specified [here](https://android.jlelse.eu/setting-up-jenkins-for-android-how-i-dealt-with-the-challenges-i-faced-1bbdb6580b8d) from Manage Jenkins -> Configure System, then check the environment variables box there and add a variable with the name ANDROID_HOME and fill the value with the path to the android SDK. – Ankur Sep 26 '19 at 10:42
  • 1
    for me I had ANDROID_PATH instead of ANDROID_HOME it worked by changing in Jenkins Config Environment, it was working before – Testing Singh Oct 08 '19 at 17:52
  • 1
    Also make sure that the variable is set for the user running gradle and that the user has access to the SDK directory. I got this error from jenkins and had to fix both of these things for the jenkins user. – Algorithm and Blues Nov 12 '19 at 11:00
12

The cause of this issue is that Gradle can't find the Android SDK. There are several ways to fix it:

Define the ANDROID_HOME environment variable

ANDROID_HOME=your/path/to/android/sdk; export ANDROID_HOME

or Add sdk.dir to the file local.properties, for example on my Linux computer

sdk.dir=/home/sdeng/Android/Sdk

If you already defined ANDROID_HOME or sdk.dir, it still happens. Its probably something is wrong with the specific version of your Android SDK or Gradle daemon. Try to kill all Gradle processes, re-download the specific version of Android SDK.

Or you can check the SDK at directory $ANDROID_HOME/platforms/android-28, where 28 is the compileSdkVersion defined in build.gradle

Sterconium
  • 559
  • 4
  • 20
sdeng
  • 151
  • 2
  • 6
2

I have figured out what the problem is. I use the build parameter 'dev' (Pbuild=dev) to make sure that the CI (Travis, in this case) uses the mock version of my google-services.json file placed in the app/src/dev folder. However, I forgot to configure the 'dev' build variant in the build.gradle files of my modules.

Solution is to add the dev build type in all modules, like this:

build.gradle

android {
  ...

  buildTypes {
    release {
      ...
    }
    debug {
      ...
    }
    dev {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

Please note that you will have to do this for all the modules in your project.

harold_admin
  • 1,117
  • 2
  • 10
  • 20
  • 2
    I'm getting a similar issue, but I don't ave any custom build types (I just have release and debug). Can you shed any light on this? How did you figure out the cause? – Tim Malseed Aug 29 '19 at 13:30
  • 1
    @TimMalseed For me the issue was in the new Gradle version apparently. Reverting `classpath ‘com.android.tools.build:gradle:3.5.0’` to `classpath ‘com.android.tools.build:gradle:3.5.0-beta03’` resolved it. – ItWillDo Aug 30 '19 at 05:57
  • @ItWillDo it does not sounds like a good approach as at some time u need to update the gradle version. P.S. struggling with same problem with Team city – Kumar Saurabh Sep 09 '19 at 14:06
1

I had to accept licenses first. Weird error.

On macOS:

yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager --licenses

For other platforms see Automatically accept all SDK licences

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
0

Even if ANDROID_HOME is set, as others suggested to do, make sure that directory is actually available. I am building in a chroot environment, and neglected to edit my chroot.sh script to account for the directory layout of my newer laptop. As a result, $HOME/Downloads, which links to a directory on my Windows partition, was a dead link, and the Android SDK was not found.

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107