I'm trying to create a command line script to run on my Android device. I'm following this answer to run the compiled kotlin file with Dalvik VM, but I'm getting the following error when I run dalvikvm -cp TestKt.zip
on adb shell:
Exception in thread "main" java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
at TestKt.main(Unknown Source:2)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"kotlin.jvm.internal.Intrinsics" on path: DexPathList[[zip file "TestKt.zip"],
nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64,
/system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 1 more
This is the simple file (Test.kt) that I'm trying to compile:
package edu.ufrn.lapps
fun main(args: Array<String>) {
println(args.size);
}
I wrote a Makefile to compile it (mainly because this is just a test, but I'll probably move to Gradle once I need dependencies):
NAME := TestKt
OUTPUT := TestKt
PKG := edu/ufrn/lapps
KFLAGS := -include-runtime
D8C := $(HOME)/Android/Sdk/build-tools/29.0.1/d8
D8FLAGS := --no-desugaring
dex:
kotlinc src/$(PKG)/Test.kt
$(D8C) $(D8FLAGS) $(PKG)/$(OUTPUT).class
zip: dex
zip $(OUTPUT).zip classes.dex
jvm:
kotlinc $(SRC)/Test.kt $(KFLAGS) -d $(OUTPUT).jar
.PHONY: clean
clean:
-rm -r META-INF/
-rm $(OUTPUT).jar $(OUTPUT).zip
I'm trying to follow the AOSP cmds to make my CLI script, but I've never compiled Java bytecode to Dex before, so I'm not sure if this is the right way to do it.
How should I go about fixing this error?