1、project 的gradle 文件中:
- 添加google()仓库,有的时候国内无法请求数据,可以使用阿里云的国内镜像仓库
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
- dependencies 中添加kotlin 的plugin
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- 版本设置,在buildscript中设置如下
ext{
ext.kotlin_version = '1.2.71'
ext.dragger_version ='2.15'
ext.supportLibVersion = '28.0.0'
}
2、项目module 的gradle文件中:
- 添加头部plugin
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' //这个是为了使用第三方插件,在依赖中用kapt方法添加
- 添加依赖中 compile 用implementation 代替,annotationProcessor 用kapt 代替(这个必须有 apply plugin: 'kotlin-kapt')
//kotlin 依赖添加
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//dagger2依赖添加
implementation "com.google.dagger:dagger:$dragger_version"
kapt "com.google.dagger:dagger-compiler:$dragger_version"