Using jdk.jshell Android Studio

21 views Asked by At

I'm working with https://github.com/FIRST-Tech-Challenge/FtcRobotController for FTC. I'm making a tool that uses JShell to evaluate code the user supplies over a socket. (It uses AES GCM, so I think it's safe.) The problem is Android Studio doesn't let me use jdk.shell. The original jbr installation lacked jshell, so I downloaded the latest JBRSDK, filename jbrsdk-17.0.10-windows-x64-b829.27.tar.gz from https://github.com/JetBrains/JetBrainsRuntime/releases/tag/jbr-release-17.0.10b829.27 and made gradle use it in File > Settings > Build, Execution, Deployment > Build Tools > Gradle as well as making JAVA_HOME point to it. From the gradle build files I'm able to access jshell. Proof:


> Configure project :TeamCode
Launching JShell execution engine threw: No ExecutionControlProvider with name 'failover' and parameter keys: [0, 1, 2]

> Task :prepareKotlinBuildScriptModel UP-TO-DATE

BUILD SUCCESSFUL in 3s

The code in build.gradle that tried to launch jshell: jdk.jshell.tool.JavaShellToolBuilder.builder().start();

Me trying to use it in the actual project:

enter image description here

How can I make it so that I can access JShell from :TeamCode? Do I just need to add permissions to AndroidManifest.xml? If I manage to access JShell, what steps must I take to make it actually useable?

(gradle build files are accessible from FtcRobotController)

I've tried:

sourceSets {
    main {
        java {
            srcDirs += 'C:\\Program Files\\Java\\jbrsdk-17.0.10-windows-x64-b829.27'
        }
    }
}

To no avail.

enter image description here

1

There are 1 answers

0
Maxwell Wang On

I don't know if the code will have missing dependencies like how using java.util.Base64 throws runtime exceptions, but I realized that jdk.jshell was a jmod so I just extracted it and packaged it in a jar and added it to build.gradle:

//
// build.gradle in TeamCode
//
// Most of the definitions for building your module reside in a common, shared
// file 'build.common.gradle'. Being factored in this way makes it easier to
// integrate updates to the FTC into your code. If you really need to customize
// the build definitions, you can place those customizations in this file, but
// please think carefully as to whether such customizations are really necessary
// before doing so.


// Custom definitions may go here

// Include common definitions from above.
apply from: '../build.common.gradle'
apply from: '../build.dependencies.gradle'

android {
    namespace = 'org.firstinspires.ftc.teamcode'

    packagingOptions {
        jniLibs.useLegacyPackaging true
    }

    compileOptions { // I added this
        sourceCompatibility JavaVersion.VERSION_17
    }

    compileSdk 32 // I added this
}

dependencies {
    implementation project(':FtcRobotController')
    annotationProcessor files('lib/OpModeAnnotationProcessor.jar')
    implementation fileTree('lib/javac.jar') // I added this
}