Could not get unknown propert for object of type gradle build android studio

2.4k views Asked by At

In my android studio project i have gradle.build file that looks exactly like

buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
        maven {
          url "https://maven.mozilla.org/maven2/"
        }
    }
    dependencies {

        classpath "com.android.tools.build:gradle:4.1.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
      implementation "org.mozilla.geckoview:geckoview-${geckoviewChannel}:${geckoviewVersion}"

    }
}

ext {
    geckoviewChannel = "nightly"
    geckoviewVersion = "85.0.20201121092754"
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

but on running ./gradlew I got error that looks like

A problem occurred evaluating root project 'My Application'.
> Could not get unknown property 'geckoviewChannel' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

I see nothing missing or wrong here. What am I missing here.

2

There are 2 answers

0
Delta George On

Project properties

ext {
    geckoviewChannel = "nightly"
    geckoviewVersion = "85.0.20201121092754"
}

are not visible inside buildscript block which is evaluated first. A potential solution is to move ext block inside buildscript block.

0
Dev-il On

This was yet another simple mistake which I managed to solve by practicing individual dependency in module_name/build.gradle as mentioned here. I had stupidly mistaken by ignoring the comment in build.gradle file of project root directory which says

dependencies {
        ...
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

So what i did was reset the build.gradle as it was initially and configure geckoview in module_name/build.gradle.