一.直接看看如何快速的让项目可以使用Kotlin步骤:

1.在app的build.gradle中添加:

apply plugin: 'com.android.application'apply plugin: 'kotlin-android'apply plugin: 'kotlin-android-extensions'android {    compileSdkVersion 28    defaultConfig {        applicationId "com.example.XXXXXX"        minSdkVersion 17        targetSdkVersion 28        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }}dependencies {    implementation fileTree(dir: 'libs', include: ['*.jar'])    implementation 'com.android.support:appcompat-v7:28.0.0'    implementation 'com.android.support.constraint:constraint-layout:1.1.3'    testImplementation 'junit:junit:4.12'    androidTestImplementation 'com.android.support.test:runner:1.0.2'    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'    implementation 'com.android.support:recyclerview-v7:28.0.0'//    编辑个人信息,使用户可以拖动和排列图像顺序    implementation 'com.github.SwiftyWang.android-drag-square:dragsquareimage:1.2.3'//    一个简单的演示应用程序,如何像滑动操作一样实现iOS Mail应用程序    dependencies {        compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.6@aar'){            transitive=true        }    }//    史上最简单侧滑菜单,0耦合,支持任意ViewGroup。一步集成侧滑(删除)菜单,高仿QQ、IOS    dependencies {        implementation ('com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0'){            transitive=true        }    }    //Adapter终结者 地址:https://github.com/mcxtzhang/all-base-adapter    implementation 'com.github.mcxtzhang:all-base-adapter:V1.5.2'    implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.18'//    滑动菜单库不仅用于recyclerview,还用于所有视图。    dependencies {        implementation ('com.github.anzaizai:EasySwipeMenuLayout:1.1.4'){            transitive=true        }    }//    //Wave,水波,Android 炫酷的多重水波纹 MultiWaveHeader//    dependencies {//        implementation ('com.scwang.wave:MultiWaveHeader:1.0.0-alpha-3'){//            transitive=true//        }//    }    //androidx//    implementation 'com.scwang.wave:MultiWaveHeader:1.0.0-andx-3'    implementation 'org.adw.library:discrete-seekbar:1.0.0'//    粒子动画    implementation 'me.wangyuwei:ParticleView:1.0.4'    //下拉刷新上拉加载框架    implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-21'    //圆形图片头像框架    implementation 'de.hdodenhof:circleimageview:2.0.0'    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"    implementation 'com.android.support:design:28.0.0'    implementation 'com.android.support:support-v4:28.0.0'    //用来检查 Activity 的生命周期,而不必强依赖 Activity    implementation "android.arch.lifecycle:viewmodel:$lifecycle_runtime_version"    implementation "android.arch.lifecycle:livedata-core:$lifecycle_runtime_version"    implementation "android.arch.lifecycle:extensions:$lifecycle_runtime_version"}

可以看出,需要添加:

apply plugin: 'kotlin-android'apply plugin: 'kotlin-android-extensions'
 implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

2.在项目的build.gradle中添加:

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {//    ext.kotlin_version = '1.3.50'    ext.kotlin_version = '1.2.30'    ext.coroutinesVersion = '1.2.2'    ext.lifecycle_runtime_version = "1.1.0"    repositories {        google()        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:3.1.3'        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    }}allprojects {    repositories {        google()        jcenter()        maven { url 'https://jitpack.io' }    }}task clean(type: Delete) {    delete rootProject.buildDir}

可以看出,添加:
 

 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

二.问题解决:

检查Kotlin的版本号是否一致,不一致会报错的,改为一致即可

还可以:File -> Invalidate Caches / Restart 。重启之后,Build -> Rebuild Project。

更多相关文章

  1. 常用的Android(安卓)Widget组件学习③-checkbox和radiogroup的介
  2. android 拦截器
  3. BLE 扫描及连接 android程序开发(一)
  4. Android中View的事件分发机制
  5. android待机添加电量小部件,点击位置信息图标,模式切换需要改为四
  6. Android设置Toast长时间显示,及AlertDialog的使用
  7. Android(安卓)studio--Android开发添加外来字体库
  8. APICloud SuperWebView融合Android原生平台
  9. 【30篇突击 android】源码统计 十九

随机推荐

  1. android EditText+ListView的组合(类似于A
  2. Android调用js的坑
  3. Manpower代招-高级Android开发工程师@成
  4. android 读取assets指定文件
  5. Android(安卓)Activity之间跳转出现短暂
  6. android关于加载本地html5的问题(解决办
  7. Android 实现仿Window7图片预览窗格效果
  8. Android WebView在系统进程中无法使用
  9. Android 多行跑马灯 解决焦点抢占
  10. Android中短信的收发机制 发送短信 接收