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”?>
<my.package.BetterViewAnimator
  android:id=“@id/switcher”
  xmlns:android=“http://schemas.android.com/apk/res/android”
  android:layout_width=“match_parent”
  android:layout_height=“match_parent”
  >

  <ProgressBar
  android:id=“@+id/progress”
  android:layout_width=“wrap_content”
  android:layout_height=“wrap_content”
  android:layout_gravity=“center”
  />

  <android.support.v7.widget.RecyclerView
  android:id=“@+id/list”
  android:layout_width=“match_parent”
  android:layout_height=“match_parent”
  />

  <include
  android:id=“@+id/auth_error”
  layout=“@layout/view_my_tasks_auth_error”
  />

  <include
  android:id=“@+id/error”
  layout=“@layout/view_tasks_network_error”
  />

  <include
  android:id=“@+id/empty”
  layout=“@layout/view_my_tasks_empty”
  />

</my.package.BetterViewAnimator>

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 {
        jcenter()
    }
    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 {
  jcenter()
  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:checkDebugManifest
: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:prepareDebugDependencies
: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
:app:compileDebugKotlin
/home/yoavst/Documents/AndroidStudioProjects/WhatismyIP/app/src/main/kotlin/com/yoavst/whatismyip/ItemView.kt
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

/home/yoavst/Documents/AndroidStudioProjects/WhatismyIP/app/src/main/kotlin/com/yoavst/whatismyip/MainActivity.kt
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

+1

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?)