Help us understand the problem. What is going on with this article?

AndroidプロジェクトのKotlin化

More than 3 years have passed since last update.

前置き

ただのメモ。
基本は、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
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした