在项目的app下的build.gradle文件中
apply plugin:'com.android.application'//创建项目自带的
//下边三个是使用Kotlin开发用到的
apply plugin:'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin:'com.goole.gms.oss.licenses.plugin'
会报:Plugin with id 'kotlin-android' not found、Plugin with id 'com.google.gms.oss.licenses.plugin' not found.
需要在项目下的build.gradle文件中添加如下
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version="1.3.30"//添加
repositories {
maven { url 'https://maven.google.com/'}
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0-alpha04'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"//添加
classpath "com.google.gms:oss-licenses:0.9.2"//添加
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com/'}
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
参考网址:https://www.cnblogs.com/zhoushasha/p/10952148.html
https://blog.youkuaiyun.com/S_clifftop/article/details/103048695
1.kotlin报错:Only safe (?.) or non-null asserted (!!.)
参考网址:https://www.jianshu.com/p/c568b0c46e86
原来:
mapStatusBuilder.target(target.getMap("center").toLatLng())
修改后:
mapStatusBuilder.target(target.getMap("center")!!.toLatLng())
2.Android Studio 中kotlin文件转换成Java
参考网址:https://blog.youkuaiyun.com/qq_28334473/article/details/79081709
Kotlin 转换Java文件
Tools>Kotlin>Show Kotlin Bytecode
Decompile
Java转换kotlin文件(需要studio3.0)或者安装了kotlin插件。
选择页面的要转的文件
第一种 Ctrl+Shift+Alt+K
第二种 Code - Convert Java File To Kotlin File