如何让Java Android工程支持Kotlin

1、打开项目的build.gradle,补充添加kotlin的版本号声明

buildscript {

    ext.kotlin_version = '1.4.31'

    repositories {

        google()

        //jcenter()

        maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' }

        maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}

        maven { url 'https://jitpack.io' }

    }

    dependencies {

        classpath 'com.android.tools.build:gradle:4.1.1'

        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

        classpath 'com.github.canwen2003:module_plugin:v1.0.0.0'

    }

}

2、打开模块的build.gradle,在文件开头补充添加Kotlin的扩展插件

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

接着在dependencies节点下补充添加Kotlin插件的编译说明:

//Kotlin

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。