Unable to add Kotlin Android Extensions to my project

半世苍凉 提交于 2020-06-13 19:35:25

问题


When i try to add kotlin-android-extensions via:

apply plugin: 'kotlin-android-extensions'

to my project Android Studio tells me Plugin with 'kotlin-android-extensions not found??

What is going wrong? I am Running Android Studio 3.0 Canary 8


回答1:


I think it's all about ordering, make sure you have plugin orders like that

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



回答2:


Please also consider that you must be careful about apply plugin: orders:

So in order to apply kotlin-android-extensions you must first apply kotlin-android. Same as the following coode:

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



回答3:


you are all done good but you have to add the plugin id to dependencies classpath in your gradle file like this

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

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

you always have to add that and after doing this, add the following in your gradle(app) file

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

and you are all done




回答4:


In your gradle app:

apply plugin: 'kotlin-android-extensions'

and in your activity:

import kotlinx.android.synthetic.main.height_dialog_ft.*

Then you can use any id in your activity directly by their id name which your have mentioned in your .xml file




回答5:


Ooops. I forgot to add the kotlin gradle plugin as mentioned here: https://kotlinlang.org/docs/reference/using-gradle.html#plugin-and-versions



来源:https://stackoverflow.com/questions/45400842/unable-to-add-kotlin-android-extensions-to-my-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!