Android中关于使用Kotlin

在项目的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 foundPlugin 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.csdn.net/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.csdn.net/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 
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值