Android support in kotlinc cli?

Is there any documentation about how to use kotlinc cli with Android support? The only thing I can find online is a very old reddit reply[1], and kotlin-android-compiler-plugin it mentioned was last updated on 2015-03-10 on maven[2], that’s 2 years ago! Also I cannot get it to work with kotlinc 1.1.0:

$ kotlinc -Xplugin ../kotlin-android-compiler-plugin-0.10.1316.jar -P plugin:org.jetbrains.kotlin.android:androidManifest=AndroidManifest.xml -P plugin:org.jetbrains.kotlin.android:androidRes=res/ main.kt
exception: java.lang.NoClassDefFoundError: kotlin/jvm/internal/KObject
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at org.jetbrains.kotlin.cli.jvm.PluginURLClassLoader$SelfThenParentURLClassLoader.findClass(PluginCliParser.kt:120)
	at org.jetbrains.kotlin.cli.jvm.PluginURLClassLoader.loadClass(PluginCliParser.kt:102)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at kotlin.collections.CollectionsKt___CollectionsKt.toCollection(_Collections.kt:1038)
	at kotlin.collections.CollectionsKt___CollectionsKt.toMutableList(_Collections.kt:1071)
	at org.jetbrains.kotlin.cli.jvm.PluginCliParser.loadPlugins(PluginCliParser.kt:41)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:72)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
	at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:191)
	at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:138)
	at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:65)
	at org.jetbrains.kotlin.cli.common.CLICompiler.doMainNoExit(CLICompiler.java:402)
	at org.jetbrains.kotlin.cli.common.CLICompiler.doMain(CLICompiler.java:386)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:287)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.jetbrains.kotlin.preloading.Preloader.run(Preloader.java:73)
	at org.jetbrains.kotlin.preloading.Preloader.main(Preloader.java:35)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.KObject
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:75)
	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:82)
	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:75)
	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:82)
	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:75)
	at org.jetbrains.kotlin.preloading.MemoryBasedClassLoader.loadClass(MemoryBasedClassLoader.java:82)
	at org.jetbrains.kotlin.cli.jvm.PluginURLClassLoader$SelfThenParentURLClassLoader.findClass(PluginCliParser.kt:123)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 35 more

Any help is appreciated.

[1] https://www.reddit.com/r/Kotlin/comments/3h6u85/android_extensions_from_command_line_compiler/cu4ve4c/
[2] Maven Central Repository Search

What are you trying to accomplish? For building Android projects, we only support Gradle.

What version of Android Extensions plugin do you use? Looks like it’s Kotlin M10 (pre-1.0).
Please use the actual version of the Android Extensions compiler plugin: Release 1.1.1 · JetBrains/kotlin · GitHub (use the link in Downloads).

I was trying to add bazel support.

I tried that, but are still getting troubles:

$ kotlinc -Xplugin ~/work/homebrew/Cellar/kotlin/1.1.1/libexec/lib/android-extensions-compiler.jar -P plugin:org.jetbrains.kotlin.android:variant=debug -P plugin:org.jetbrains.kotlin.android:package=com.yhsif.autonotif .
src/com/yhsif/autonotif/main.kt:4:8: error: unresolved reference: android
import android.app.Activity;
       ^
src/com/yhsif/autonotif/main.kt:5:8: error: unresolved reference: android
import android.os.Bundle;
       ^
src/com/yhsif/autonotif/main.kt:7:29: error: unresolved reference: Activity
public class MainActivity : Activity() {
                            ^
src/com/yhsif/autonotif/main.kt:9:3: error: 'onCreate' overrides nothing
  override fun onCreate(savedInstanceState: Bundle?) {
  ^
src/com/yhsif/autonotif/main.kt:9:45: error: unresolved reference: Bundle
  override fun onCreate(savedInstanceState: Bundle?) {
                                            ^
src/com/yhsif/autonotif/main.kt:10:11: error: unresolved reference: onCreate
    super.onCreate(savedInstanceState)
          ^
src/com/yhsif/autonotif/main.kt:11:5: error: unresolved reference: setContentView
    setContentView(R.layout.myq)
    ^
src/com/yhsif/autonotif/main.kt:11:20: error: unresolved reference: R
    setContentView(R.layout.myq)
                   ^

It still looks like kotlinc isn’t aware of Android at all. Is there any parameters I’m missing?

I’m not sure about the correct syntax, but to make things work, you will have to tell the compiler not to use the jdk library, but to use the sdk library instead. As @yole said building Android without a build system is unsupported (and probably crazy as well). There are various moving parts that are more complicated than to get the compiler going.