2

I'm learning android data binding. The problem I'm facing is that in case of errors related to data binding with my current setup I'm getting very general error messages which give no clue of what and where has happened exactly instead of very specific ones that were mentioned in some topics on data binding (for instance).

Consider following layout:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <!--<import type="android.view.View"/>-->
        <!--<import type="android.text.TextUtils"/>-->
        <variable
            name="movie"
            type="us.kostenko.architecturecomponentstmdb.details.model.Movie" />
    </data>
    <TextView
        <!-- ... -->
        android:text="@{TextUtils.isEmpty(movie.release_date) ? @string/empty_date : movie.release_date}"/>
</layout>

Note that imports are commented out on purpose to trigger an error.

I expected to get something like Identifiers must have user defined types from the XML file. TextUtils is missing it error. But the error I'm getting is very general one:

    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptDebugKotlin'.
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
    at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:16)
    at org.jetbrains.kotlin.gradle.internal.KaptWithKotlincTask.compile(KaptWithKotlincTask.kt:79)

I suspect there's something wrong with my setup. I'm using Android studio 3.1.4.

Here's my build.gradle

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'kotlin-android-extensions'
    android {
    //...
        dataBinding { enabled = true }
    }

    dependencies {
        // ...
        kapt "com.android.databinding:compiler:3.1.4"
    }

And the project level one:

buildscript {
ext.kotlin_version = '1.2.70'
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

Any ideas what I'm missing here?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
AlexKost
  • 2,792
  • 4
  • 22
  • 42
  • Is movie.release_date a String? maybe it is confused because you are giving text both as a string reference (@string/empty_date) and as a String object (movie.release_date). If that's the case, I would also expect a more precise exception log though. – gizembrh Oct 08 '18 at 22:13

1 Answers1

0

Here is mine, that is working fine, gives appropriate error, there is not too much difference. Try this...

app-level build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
    }
    dataBinding {
        enabled = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
    mavenCentral()
}

project-level build.gradle

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

buildscript {
    ext.kotlin_version = '1.2.70'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • The differences are minor. I've tried to apply them, no luck though. – AlexKost Sep 22 '18 at 10:33
  • No. The problem is that I'm getting general errors that do not point to the problem itself nor to the code in question instead of specific ones. Details explained in the question above. – AlexKost Sep 22 '18 at 13:35
  • Okay okay, i got that, i faced this when I started binding, check my this answer, i explained there, https://stackoverflow.com/a/51579759/6891563 – Khemraj Sharma Sep 22 '18 at 13:43