dzboot02
dzboot02

Reputation: 2979

Gradle Plugin 3.2.0 with databinding, can not resolve package name

After updating Android Studio from 3.1.2 to 3.2.0, and updating the gradle plugin with it to 3.2.0, I am having a problem with a generated databinding classes which are complaining about a package name that does not exist, but it does exist. The package belongs to a module in the project.

Here are the errors that I am getting when trying to run the app:

error: cannot find symbol class Helper

error: package Helper does not exist

This is my project level build.gradle file:

buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath "com.google.gms:google-services:4.0.1"
        classpath 'io.fabric.tools:gradle:1.25.4'

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

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

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

And this is the build.gradle for the module which having the problem:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 28
    }
}

dependencies {
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

I tried all sort of things:

None did work.

EDIT: added screenshotenter image description here

Upvotes: 4

Views: 1747

Answers (3)

WasabiTea
WasabiTea

Reputation: 389

I had the SAME ISSUE today.

The problem is your package name itself. You mentioned:

there is no Helper class in my project, it is a package name. The package does exist, but databinding can't find it.

Short Answer:

Change your package name that starts with a lower case letter. The problem happens because your package name is Helper. Change it to helper.

Long Answer:

In Android Plugin 3.2.0 and above, the databinding V2 is enabled by default. I guess the databinding V2 compiler treats any component that starts with an upper case letter as a class, not a package. It is actually looking for a class with a name Helper, not the package Helper.

Because you were using Android 3.1.2 before, which is using the databinding V1 compiler, the package name wasn't an issue.

I renamed all my package(folder) names in my project to start with a lower case letter and the project was finally compiled. Make sure to use the refactor tool (Shift + F6) when you rename the packages so that the change can be applied to your XML files also!!

BONUS:

Just in case you want to keep the package names to start with upper case letters, but also want to use the Android Plugin 3.2.0 (which is not really recommended), go to gradle.properties in the root folder and add this line. This disables the databindingV2 compiler and forces the project to use the old V1 compiler. Therefore your class name won't matter.

android.databinding.enableV2=false

But why would anyone want to do this? :/

Upvotes: 5

Vít Kapitola
Vít Kapitola

Reputation: 549

I am using the Highcharts library (https://github.com/highcharts/highcharts-android) and I found the same problem with databinding - import after updating the gradle plugin to 3.2.0.

This version has probably errors included, so stay with the version 3.1.3.

The databinding file in version 3.2.0 :

import error in gradle 3.2.0

The databinding file in version 3.1.3:

import OK in gradle 3.1.3

Upvotes: 1

ʍѳђઽ૯ท
ʍѳђઽ૯ท

Reputation: 16976

In your codes, it's actually using EmojiIconEdittext helper class which comes from supernova library but in your dependencies, there is no such dependency added in there.

So, add this to your Build.gradle dependencies:

implementation 'com.github.hani-momanii:SuperNova-Emoji:1.1'

Or remove the class (If you don't wanna use it) and then it will work fine.

P.S: The import actually tells the truth.

import supernova.emoji.helper

Upvotes: 0

Related Questions