Hey guys! I’m current working on my robotics team ...
# scripting
w
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
Oops sorry I just deleted my message, I just understood 😅
I think that should work ?
w
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
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
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
w
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
I actually watched this but this seemed very Gradle oriented.
You're not planning to run Gradle on an Android device, are you?
w
well i do run a gradle build to build and install to the phone
m
Yep, but that runs on a laptop, right?
w
oh yea your right
m
Where is android involved ?
w
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
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
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
that gets me wondering if it's possible to turn a kts file into a .class file...
w
that would take off the load on the phones memory right? since we are doing that during compilation which is on the laptop
m
No worries, sorry I haven't been super helpful, I should rewatch that talk!
w
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
For Android you'd need more than a class file, Android uses its own bytecode format that's called dex
w
that is true, but if we can get to .class its a step in the right direction for sure
m
Sticking with the standard way to do apps feels simpler
w
that is probably a good idea
n
Iirc you can use a gradle plugin to compile kts files and then use them from other modules
w
i thought i added the correct gradle plugins but i got a gradle memory exceeded error?
n
Then you may need to give gradle more memory to work with
That can be done in the gradle.properties
w
you see, i would, but im building to a phone, so im limited there
n
gradle memory exceeded error
this is something at compile/build time on your laptop though
☝️ 1
g
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
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
Java8 will not workl probably, until API 23 (?)
m
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?