Skip to content

integration with android studio classpathΒ #120

@davidhewitt

Description

@davidhewitt

I have a toy android app for which I implement as much functionality as I can in Rust, with a Kotlin UI on the top. I use the rust-android-gradle plugin to make the build work in Android Studio, which has been relatively smooth sailing for several years now.

I am not at all a gradle expert, so I had to fight a bit (with the help of ChatGPT 😬) to get some configuration for rust-android-gradle to feed the right environment for duchess.

I thought I'd share it here in case anyone has better ideas on how to integrate a project using duchess into an android app, and also in case anyone else is trying this sort of thing. Also feel free to treat this just as informational and close the issue πŸ˜„

cargo {
    module = "../../client-lib"
    libname = "toyproject"
    targets = ["arm64"]
    targetDirectory = "../../target"
    exec { spec, toolchain ->
        // Classpath of the android SDK
        def classPath = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"

        // Classpath of the build outputs
        android.applicationVariants.all { variant ->
            variant.outputs.each { output ->
                // Java outputs (if you have any java files)
                classPath += ";${variant.javaCompileProvider.get().destinationDir}"

                // Kotlin outputs (if you have any kotlin files)
                def kotlinTaskName = "compile${variant.name.capitalize()}Kotlin"
                def kotlinTask = tasks.named(kotlinTaskName).get()
                if (kotlinTask) {
                    classPath += ";${kotlinTask.outputs.files.join(";")}"
                }
            }
        }
        spec.environment("CLASSPATH", classPath)
        
        // Set JAVA_HOME so that duchess can find javap
        spec.environment("JAVA_HOME", System.getProperty('java.home'))
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions