Kotlin框架--配置及ButterKnife无效问题
来源:互联网 发布:java hsv色彩转rgb 编辑:程序博客网 时间:2024/06/08 07:38
一、studio项目引入Kotlin框架--配置:(下载具体不详解可参考其他文档
http://www.runoob.com/kotlin/otlin-android-setup.html)
1、执行 Settings -> plugins -> BrowseRepositories中搜索“Kotlin”
2、安装Kotlin和Kotlin Extensions…
3、Kotlin插件安装成功后,执行new操作,-“KotlinFile/Class”:一般Kotlin类-“Kotlin Activity”:Activity类
4、配置Kotlin
当我们第一次创建一个Kotlin类或者转化,会弹出提示Configure Kotlin的弹窗:
点击并按照提示步骤即可;
然后等待同步完成--可能需要等待一段时间
至此配置完成;可以在gradle中查看:
buildscript { ext.kotlin_version = '1.1.3-2' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.2' 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 }}
apply plugin: 'kotlin-android'
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') ……………………………… compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"}repositories { mavenCentral()}
然后就可以新建开发了;
当然不能忘了 Studio中Java和Kotlin代码互转方式
执行code–> Convert Java File to Kotlin File
二、Kotlin使用ButterKnife无效问题
Kotlin中直接使用ButterKnife的注解方式的话,会出现空指针的异常,导致绑定失败。
所以就有——KotterKnife(代码转化或新建并且不影响之前代码)
1、 主目录build.gradle文件:已生成
buildscript {
ext.kotlin_version = '1.1.3-2'
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
2、项目的gradle配置文件中加入
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
dependencies {
compile 'com.jakewharton:butterknife:7.0.1'
//这个插件是建立在ButterKnife7的基础上的
compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
最后修改:
repositories {
//mavenCentral()---添加是自己生成的
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
使用方式如下:
在onCreate方法里,添加
ButterKnife.bind(this@MainActivity)
绑定控件---转化自动生成方式:
@Bind(R.id.title)
internal var title: TextView? = null
@Bind(R.id.recycleview)
internal var recycleview: RecyclerView? = null
阅读全文
0 0
- Kotlin框架--配置及ButterKnife无效问题
- 一脸懵逼之Kotlin使用ButterKnife无效问题
- butterknife在eclipse配置讲解(解决ButterKnife.bind初始化无效问题)
- butterknife在eclipse配置讲解(解决ButterKnife.bind初始化无效问题)
- 在Kotlin下使用ButterKnife框架
- Android butterknife框架配置
- ButterKnife框架问题
- ButterKnife 配置及使用
- 在Kotlin的语言环境下使用ButterKnife框架
- Android Studio使用ButterKnife 8.0.1无效的问题
- Android Studio使用ButterKnife 8.6.0无效的问题
- kotlin 的配置及使用
- ButterKnife及插件 在studio中的 配置
- Android Studio配置ButterKnife及 基本使用
- 框架 butterknife
- ButterKnife框架
- ButterKnife无效 空指针
- 解决Android4.4及以下Volley框架Patch请求报错问题(Kotlin)
- SQL中INNER、LEFT、RIGHT JOIN的区别和用法详解
- Linux下undefined reference to ‘pthread_create’问题解决
- FCC学习笔记-(二) Responsive Design with Bootstrap
- opencv: 获取 图像属性 (源码)
- 设计模式-结构型模式总结
- Kotlin框架--配置及ButterKnife无效问题
- thinkphp3.2 join复杂链表查询语句(表重命名/别名)
- codeforces 377A Maze(广搜)
- 基于SSM的Android后台开发
- Generalized Low Rank Approximations of Matrices
- Android_Intent的属性
- Spring和springmvc父子容器注解扫描问题详解
- 注意头文件规则,避免链接错误:重复定义(multiple defination)
- Java微信分享接口开发