Avik Chowdhury
Avik Chowdhury

Reputation: 198

Could not get unknown property 'supportLibraryVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

I added an external library to my android project. After gradle sync I got the following error:

ERROR: Could not get unknown property 'supportLibraryVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

This is the build.gradle file of the library I added:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion "28.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/base'
        main.java.srcDirs += 'src/main/api9'
        main.java.srcDirs += 'src/main/api14'
        main.java.srcDirs += 'src/main/api21'
        main.java.srcDirs += 'src/main/api23'
    }
}

dependencies {
    implementation "com.android.support:support-annotations:$supportLibraryVersion"
    implementation "com.android.support:support-v4:$supportLibraryVersion"

    // Tests
    testCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test:runner:0.5') {
        exclude module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
        exclude module: 'support-annotations'
    }
}

The supportLibraryVersion was declared in my app gradle file as follows:

ext {
    supportLibraryVersion = '27.1.0'
}

I tried to manually declare the supportLibraryVersion in the gradle file.

implementation "com.android.support:support-annotations: '27.1.0'"
implementation "com.android.support:support-v4:'27.1.0'"

Then the following error occurs:

ERROR: Failed to resolve: com.android
Affected Modules: library

Upvotes: 6

Views: 14098

Answers (2)

Emdadul Sawon
Emdadul Sawon

Reputation: 6077

For your first problem, you did not declare property $supportLibraryVersion in your library's build.gradle file. You need to declare this property like below

ext {
    supportLibraryVersion = '27.1.0'
}

For your second problem, you need to remove quote around the dependency version. So you need to rewrite dependency like below-

implementation "com.android.support:support-annotations:27.1.0"
implementation "com.android.support:support-v4:27.1.0"

Upvotes: 3

karan
karan

Reputation: 8843

You need to use single-quote when defining statically.

implementation 'com.android.support:support-annotations:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'

Upvotes: 0

Related Questions