Kotlin android extensions plugin cant parse my layouts

Really like this feature, but can't make it work in my project.

alots of compiler errors, but only 3 different types

  • Error:Unresolved reference: include - not supported?
  • Error:Redeclaration: drawer_layout - i can handle it, my fault
  • Error:Unresolved reference: ViewStub - not supported?
what can i do with it?

Same for me, plugin installed, classpath was added.

Error:(8, 8) Unresolved reference: kotlinx

Could you please provide an XML file with <include> tags which can't be parsed? I've tried to use <include>, and it works as should.

By the way, what IDEA/Android Studio version are you using?

Yeah, sorry:

Android Studio 1.1.0

I have multiple layouts with includes, for example:

<?xml version=‚Äú1.0‚ÄĚ encoding=‚Äúutf-8‚ÄĚ?>







I dont have any include Latest android studio beta

Is Kotlin configured in the Android project? You can test it with: Tools -> Kotlin -> Configure Kotlin in Project.

<include> tags with ids are not supported yet, sorry. It will be fixed in near future.

All modules with kotlin files are configured

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

buildscript {
    repositories {
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

allprojects {
  repositories {
  maven {
¬†¬†¬†¬†¬†¬†¬†¬† ¬†¬†url ‚Äúhttps://jitpack.io‚ÄĚ

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: 'https://gist.githubusercontent.com/stefanhoth/37f86c8e41d648cbd2c8/raw/49ca13d028885cae89f7da949f11069365aefeec/idea-gradle-sources.gradle'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"

    defaultConfig {
        applicationId "com.yoavst.whatismyip"
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 2
        versionName "1.1"
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        debug.java.srcDirs += 'src/debug/kotlin'
        release.java.srcDirs += 'src/release/kotlin'

  lintOptions {
  abortOnError false

dependencies {
¬†¬†compile fileTree(dir: ‚Äėlibs‚Äô, include: [‚Äô*.jar‚Äô])
¬†¬†compile ‚Äėcom.android.support:appcompat-v7:22.0.0‚Äô
¬†¬†compile ‚Äėcom.android.support:cardview-v7:22.0.0‚Äô

¬†¬†compile ‚Äúorg.jetbrains.kotlin:kotlin-android-sdk-annotations:$kotlin_version‚ÄĚ
¬†¬†compile ‚Äúorg.jetbrains.kotlin:kotlin-stdlib:$kotlin_version‚ÄĚ
¬†¬†compile ‚Äėcom.github.yoavst:androidKotlin:v1.0.3‚Äô

¬†¬†compile ‚Äėcom.github.kevinsawicki:http-request:5.6‚Äô
¬†¬†compile ‚Äėcom.github.xiprox.errorview:library:1.0.0‚Äô

Information:Gradle tasks [:app:compileDebugSources, :app:compileDebugAndroidTestSources]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72200Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:app:prepareComGithubXiproxErrorviewLibrary100Library UP-TO-DATE
:app:prepareComGithubYoavstAndroidKotlinV103Library UP-TO-DATE
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
Error:(8, 8) Unresolved reference: kotlinx
Error:(22, 9) Unresolved reference: title
Error:(23, 9) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val <K, V> kotlin.Map.Entry<???, ???>.value: ??? defined in kotlin

Error:(12, 8) Unresolved reference: kotlinx
Error:(22, 29) Unresolved reference: toolbar
Error:(23, 9) Unresolved reference: refresh
Error:(56, 13) Unresolved reference: progress
Error:(57, 13) Function invocation ‚Äėerror(‚Ķ)‚Äô expected
Error:(57, 13) No value passed for parameter message

Warning:(57, 19) Unreachable code
Warning:(58, 13) Unreachable code

Error:(58, 18) Unresolved reference: show

Warning:(59, 13) Unreachable code

Error:(65, 29) Unresolved reference: externalIp
Error:(66, 29) Function invocation ‚ÄėconnectionType(‚Ķ)‚Äô expected
Error:(66, 29) No value passed for parameter type
Error:(66, 44) Unresolved reference: setData
Error:(67, 29) Unresolved reference: internalIp
Error:(68, 29) Unresolved reference: hostName
Error:(69, 29) Unresolved reference: dns
Error:(70, 29) Unresolved reference: progress
Error:(106, 9) Function invocation ‚Äėerror(‚Ķ)‚Äô expected
Error:(106, 9) No value passed for parameter message

Warning:(106, 15) Unreachable code
Warning:(107, 9) Unreachable code

Error:(107, 14) Unresolved reference: hide
Error:(108, 9) Unresolved reference: externalIp

Warning:(108, 9) Unreachable code

Error:(109, 9) Unresolved reference: progress

Warning:(109, 9) Unreachable code
:app:compileDebugKotlin FAILED

Error:Execution failed for task ‚Äė:app:compileDebugKotlin‚Äô.
> Compilation error. See log for more details
Information:BUILD FAILED
Information:Total time: 11.504 secs
Information:24 errors
Information:7 warnings
Information:See complete output in console

I see! Please try to move buildscript Kotlin dependencies to the app/build.gradle file (https://gist.github.com/yanex/573f2ff27f2ee5604834). It solved the compilation problem on my test project with these build.gradle files.

I was experiencing the same problem, moving the buildscript configuration to the same build.gradle file resolved it for me. Just out of curiosity, why is this necessary?

Moving gradle dependencies to app/build.gradle helped me to get rid of import errors, while I'm still unable to get code work. I've got plenty of errors like this:

Error:(26, 9) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
internal val android.app.Fragment.salaryEdit: android.widget.EditText! defined in kotlinx.android.synthetic.fragment_settings
internal val android.app.Activity.salaryEdit: android.widget.EditText! defined in kotlinx.android.synthetic.fragment_settings

Seems that plugin generates layout bindings only for core android classes like android.app.Activity and android.app.Fragment, while I'm using replacements from support library: android.support.v7.app.ActionBarActivity and android.support.v4.app.Fragment, which are not always subclasses of core classes

It works fine for me in ActionBarActivity

Yes, it should work well with ActionBarActivity, because it's subclass of Activity; but Fragment from support library doesn't subclass android.app.Fragment, so all fragments derived from android.support.v4.app.Fragment won't resolve views.

Why does it works?

We decided not to support android.support.v4.app.Fragment because it is useful only for Android 2.3. You can use synthetic properties for View receiver (getView().textView), if you import kotlinx.android.synthetic.fragment_settings.view.*. However, properties for Views are not cached.

> it is useful only for Android 2.3.

This is completely untrue. Ever used a ViewPager? If you want it to work with native fragments, you have to import a completely separate support library (v13). Not to mention, the v13 library doesn’t support nested fragments, so not using the support fragments would mean forfeting that functionality (at least as of Aug. 2014)

The support libraries have become integral enough to the point where many developers simply just use the support versions of core components by default in their day-to-day development. These often have more fixes for existing bugs on older versions as well, and in some cases support newer features.

I'm agree. Does the apk contains all the extenstion methods, or unused get dropped? because if they get dropped you can add it without problem. If not, you can create same code but kotlin-android-extenstions-support


It is impossible not to use support libraries right now.

Ok, that's a good argument.

Are you planning to add support library support in next release? (Or even push a quick-fix in M11 update?)