1

I'm trying data binding on Android using Kotlin but experiencing some problems. My gradle files are listed below.

Top level:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0-beta3'
        classpath 'com.google.gms:google-services:2.1.0-beta3'

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

allprojects {
    repositories {
        jcenter()
    }
}

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

App level:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "..."
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        resValue 'string', 'package_name', applicationId
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'app-release', ext: 'aar')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.android.support:recyclerview-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.google.android.gms:play-services-plus:8.4.0'
    compile 'com.google.android.gms:play-services-auth:8.4.0'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.google.android.gms:play-services-nearby:8.4.0'
    compile 'io.reactivex:rxkotlin:0.55.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'com.trello:rxlifecycle-kotlin:0.5.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'io.pristine:libjingle:11139@aar'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
    compile 'com.pushtorefresh.storio:sqlite:1.8.0'
    compile 'com.pushtorefresh.storio:content-resolver:1.8.0'

    kapt 'com.google.dagger:dagger-compiler:2.0.2'
    compile 'com.google.dagger:dagger:2.0.2'
    provided 'org.glassfish:javax.annotation:10.0-b28'
}
buildscript {
    ext.kotlin_version = '1.0.1-2'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

kapt {
    generateStubs = true
}

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

I'm using the following code to inflate my view.

val binding = FragmentTransferListBinding.inflate(inflater, container, false)

But when I try to build the project I get this error.

Error:(7, 31) Unresolved reference: databinding
Error:(28, 9) Unresolved reference: FragmentTransferListBinding
Error:Execution failed for task ':app:compileDebugKotlinAfterJava'.
> Compilation error. See log for more details

I tried adding databinding-compiler to kapt as suggested in some other answers

kapt 'com.android.databinding:compiler:2.1.0-beta3'

But then I get the following error.

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.append(Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable;
4
  • You should definitely add kapt 'com.android.databinding:compiler:2.1.0-beta3'. Try to clean and rebuild the app after that. Commented Apr 21, 2016 at 15:45
  • @Michael Yes as I've mentioned above I've already tried adding that but I'm getting a java.lang.NoSuchMethodError. Commented Apr 21, 2016 at 15:47
  • Yes, I know. I just mean it's necessary to have this line in the build.gradle. Commented Apr 21, 2016 at 15:48
  • Ok, I'll keep it but is there any solution to the NoSuchMethodError? Commented Apr 21, 2016 at 15:53

3 Answers 3

2

you need

kapt 'com.google.guava:guava:19.0'
kapt 'com.android.databinding:compiler:2.1.0'

before dagger's dependency description

Sign up to request clarification or add additional context in comments.

Comments

0

In my case adding version = "2.0.0 in

dataBinding { enabled = true version = "2.0.0" }

like referred in this issued by ubarua123 and AlokBansal8 solved the problem of NoSuchMethodError

Comments

0

Try to delete .idea, .build folder and invalidate&restart Android Studio

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.