https://kotlinlang.org logo
#scripting
Title
# scripting
w

WukongRework.exe

10/27/2020, 10:30 PM
Hey guys! I’m current working on my robotics team for highschool (FTC). This year we migrated to a 100% kotlin code base and i was wondering, Am I able to create custom kts files like something.kts for an android project? I tried originally by doing the same setup as you would for a normal JVM project but I got a gradle exceeded memory error. Is there a way for this to be possible and I just set it up incorrectly or is it not possible as of right now? Thanks 🙏
I was hoping to access some FTC specific APIs. To send commands to the robot's hardware such as powering motors or servos.
m

mbonnin

10/27/2020, 11:07 PM
Oops sorry I just deleted my message, I just understood 😅
I think that should work ?
w

WukongRework.exe

10/27/2020, 11:08 PM
i remember following the JVM setup, but i have a feeling I dont need some of the specific gradle implementations
do you know which dependencies i need to add to the gradle?
m

mbonnin

10/27/2020, 11:12 PM
Really not sure sorry, I thought you wanted to run something like *.main.kts om a device
I haven't really used a scripting host.
w

WukongRework.exe

10/27/2020, 11:12 PM
i was hoping to be able to create my own custom kts file type, i remember a kotlinconf doing the same (iirc the file types were turtle.kts and groddle.kts)
oh...ok, thanks for the information!
m

mbonnin

10/27/2020, 11:14 PM
w

WukongRework.exe

10/27/2020, 11:15 PM
yes! exactly that one
i tried my best to add all of the stuff to my build.gradle files
but this ended up with a gradle memory exceeded error
m

mbonnin

10/27/2020, 11:16 PM
I actually watched this but this seemed very Gradle oriented.
You're not planning to run Gradle on an Android device, are you?
w

WukongRework.exe

10/27/2020, 11:17 PM
well i do run a gradle build to build and install to the phone
m

mbonnin

10/27/2020, 11:17 PM
Yep, but that runs on a laptop, right?
w

WukongRework.exe

10/27/2020, 11:17 PM
oh yea your right
m

mbonnin

10/27/2020, 11:17 PM
Where is android involved ?
w

WukongRework.exe

10/27/2020, 11:17 PM
im pushing a compiled version onto the phone
i write code in android studio, then build in android studio, and then afterwards i push to the phone through android studio install
m

mbonnin

10/27/2020, 11:20 PM
I understood this talk as a way to hook into Gradle to do something like the Gradle team did with the Kotlin DSL, so not related to calling Android APIs
w

WukongRework.exe

10/27/2020, 11:21 PM
yea, i was hoping to be able to use it as a base line but that died very quickly.
i guess, until i hear about official support for android devices, i'll have to shelve this idea
thanks for the information!
m

mbonnin

10/27/2020, 11:21 PM
that gets me wondering if it's possible to turn a kts file into a .class file...
w

WukongRework.exe

10/27/2020, 11:22 PM
that would take off the load on the phones memory right? since we are doing that during compilation which is on the laptop
m

mbonnin

10/27/2020, 11:22 PM
No worries, sorry I haven't been super helpful, I should rewatch that talk!
w

WukongRework.exe

10/27/2020, 11:22 PM
i should also rewatch as well XD
dont worry about it, this seems to be a very abstract concept that people havent tried out extensively
m

mbonnin

10/27/2020, 11:23 PM
For Android you'd need more than a class file, Android uses its own bytecode format that's called dex
w

WukongRework.exe

10/27/2020, 11:24 PM
that is true, but if we can get to .class its a step in the right direction for sure
m

mbonnin

10/27/2020, 11:24 PM
Sticking with the standard way to do apps feels simpler
w

WukongRework.exe

10/27/2020, 11:24 PM
that is probably a good idea
n

Nikky

10/28/2020, 6:38 PM
Iirc you can use a gradle plugin to compile kts files and then use them from other modules
w

WukongRework.exe

10/28/2020, 6:39 PM
i thought i added the correct gradle plugins but i got a gradle memory exceeded error?
n

Nikky

10/28/2020, 6:41 PM
Then you may need to give gradle more memory to work with
That can be done in the gradle.properties
w

WukongRework.exe

10/28/2020, 6:42 PM
you see, i would, but im building to a phone, so im limited there
n

Nikky

10/28/2020, 7:31 PM
gradle memory exceeded error
this is something at compile/build time on your laptop though
☝️ 1
g

gildor

10/29/2020, 6:52 AM
For Android you’d need more than a class file, Android uses its own bytecode format that’s called dex
Android is able to dynamically load .class files using dexclassloader, so it’s not a problem
m

mbonnin

10/29/2020, 11:19 AM
Looking at https://android.googlesource.com/platform/libcore-snapshot/+/refs/heads/ics-mr1/dalvik/src/main/java/dalvik/system/DexClassLoader.java, it says:
Copy code
A class loader that loads classes from {@code .jar} and {@code .apk} files
containing a {@code classes.dex} entry.
Would that still work with jars containing regular Java6 bytecode?
I'm assuming Java8 would not work in all cases because most of it requires desugaring
g

gildor

10/29/2020, 12:13 PM
Java8 will not workl probably, until API 23 (?)
m

mbonnin

10/29/2020, 1:33 PM
But Java6 bytecode will? That class I linked is talking about
classes.dex
. Is there something that can do Java8 Bytecode -> dex bytecode on device?
10 Views