LoginSignup
23
25

More than 5 years have passed since last update.

AndroidプロジェクトのKotlin化

Last updated at Posted at 2015-07-09

前置き

ただのメモ。
基本は、Kotlin のサイトの通り

Android Studio pluginをinstall

Android Studio > Preferences > Plugins > Browse Repository

browse_repository.png

下記2つをinstall

  • Kotlin
  • Kotlin Extensions for Android

kotlin_install.png

Android Studioは一度リスタートする

build.gradleの編集

buildscriptにclasspathの追加

build.gradle
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.613'
    }
}

pluginを適用

build.gradle
apply plugin: 'kotlin-android'

runtimeを追加

build.gradle
dependencies {
  compile 'org.jetbrains.kotlin:kotlin-stdlib:0.12.613'
}

.java => .kt ファイルへの変換

  • 対象のファイルを選ぶ
  • Cmd + Shift + A を押してクイックアクションを起動
  • convert files to kotlin と入力.
  • Enterでconvertできる

input_kotlin.png

build

./gradlew assembleDebug してみてビルドできれば成功。

途中で下記のような compileDebugKotlin ってタスクが挟まるっているはず。

:app:compileDebugKotlin UP-TO-DATE
23
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
25