Skip to content

Kotlin

Installation

sudo pacman -S kotlin

Dependencies

sudo pacman -S jdk17-openjdk clang cmake ninja
sudo archlinux-java set java-17-openjdk

Getting Android SDK using sdkmanager

~/.zshrc
export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$HOME/Android/Sdk/cmdline-tools/latest/bin:$PATH"

Scroll down to "Command line tools only" in https://developer.android.com/studio. and get the download link.

mkdir -p ~/Android/Sdk/cmdline-tools
cd ~/Android/Sdk/cmdline-tools
aria2c 'https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip'
unzip commandlinetools-linux-11076708_latest.zip
mv cmdline-tools latest

Install platform-tools

For platform-tools (adb, fastboot), I prefer the arch package.

sudo pacman -S android-tools

Install build-tools

Install the minimum and maximum platform sdk you want to support. https://developer.android.com/tools/releases/platforms

I want to support from nougat (25) to latest (35).

cd ~/Android/Sdk/cmdline-tools/latest/bin
./sdkmanager 'platforms;android-35'
./sdkmanager 'platforms;android-25'

Install latest build-tools

cd ~/Android/Sdk/cmdline-tools/latest/bin
./sdkmanager 'build-tools;35.0.0'

To update all installed packages

sdkmanager --update

Language Server setup for Neovim and Arch

You need to install the language server on archlinux and configure the LSP client on neovim. Before doing that take a look at this: https://github.com/Kotlin/kotlin-lsp/blob/a949438c14cf389bbbe83271c9cbb75e7d74d230/scripts/neovim.md

kotlin-lsp PKGBUILD

Check the releases in kotlin-lsp: https://github.com/Kotlin/kotlin-lsp

PKGBUILD
pkgname=kotlin-lsp
pkgver=0.252.17811
pkgrel=1
pkgdesc='Kotlin Language Server and plugin for Visual Studio Code '
arch=('any')
url='https://github.com/Kotlin/kotlin-lsp'
license=('Apache-2.0')
depends=('jdk17-open-jdk')
source=("https://download-cdn.jetbrains.com/kotlin-lsp/0.252.17811/kotlin-0.252.17811.zip")
sha256sums=('SKIP')

package() {
  install -Dvm755 'kotlin-lsp.sh' "${pkgdir}/opt/kotlin-lsp/kotlin-lsp.sh"
  cp -r lib "${pkgdir}/opt/"
  ln -s "/opt/kotlin-lsp/kotlin-lsp.sh" "${pkgdir}/usr/bin/kotlin-ls"
}

Neovim

source: https://github.com/Kotlin/kotlin-lsp/blob/a949438c14cf389bbbe83271c9cbb75e7d74d230/scripts/neovim.md#neovim-setup

~/.config/nvim/lua/config/lspclients/kotlinls.lua
1
2
3
4
5
6
7
8
vim.lsp.config['kotlinls'] = {
    cmd = { "kotlin-ls", "--stdio" },
    single_file_support = true,
    filetypes = { "kotlin" },
    root_markers = { "build.gradle", "build.gradle.kts", "pom.xml" },
}

vim.lsp.enable('kotlinls')

And activate it by adding an entry in lspclients/init.lua

~/.config/nvim/lua/config/init.lua
...
require('config.lspclients.kotlinls')
...

The whole file (for reference):

~/.config/nvim/lua/config/init.lua
1
2
3
4
5
6
7
require('config.lspclients.dartls')
require('config.lspclients.csharpls')
require('config.lspclients.luals')
require('config.lspclients.yamlls')
require('config.lspclients.clangd')
require('config.lspclients.kotlinls')
-- require('config.lspclients.ccls')

Comments