简体   繁体   English

无法将 Kotlin Android 扩展添加到我的项目中

[英]Unable to add Kotlin Android Extensions to my project

When i try to add kotlin-android-extensions via:当我尝试通过以下方式添加 kotlin-android-extensions 时:

apply plugin: 'kotlin-android-extensions'

to my project Android Studio tells me Plugin with 'kotlin-android-extensions not found??对于我的项目,Android Studio 告诉我“找不到 kotlin-android-extensions”的插件

What is going wrong?出了什么问题? I am Running Android Studio 3.0 Canary 8我正在运行 Android Studio 3.0 Canary 8

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'

Android Studio 4.1安卓工作室 4.1

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

Please also consider that you must be careful about apply plugin: orders:还请考虑您必须小心apply plugin:命令:

So in order to apply kotlin-android-extensions you must first apply kotlin-android .所以为了应用kotlin-android-extensions你必须首先应用kotlin-android Same as the following coode:与以下代码相同:

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

you are all done good but you have to add the plugin id to dependencies classpath in your gradle file like this你们都做得很好但是你必须像这样将插件ID添加到你的gradle文件中的依赖类路径

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您总是必须添加它,然后在您的 gradle(app) 文件中添加以下内容

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

and you are all done你都完成了

In your gradle app:在你的 gradle 应用程序中:

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然后您可以直接通过您在 .xml 文件中提到的 ID 名称在您的活动中使用任何 ID

Ooops.糟糕。 I forgot to add the kotlin gradle plugin as mentioned here: https://kotlinlang.org/docs/reference/using-gradle.html#plugin-and-versions我忘了添加此处提到的 kotlin gradle 插件: https ://kotlinlang.org/docs/reference/using-gradle.html#plugin-and-versions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM