Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration with android studio classpath #120

Open
davidhewitt opened this issue Nov 3, 2023 · 0 comments
Open

integration with android studio classpath #120

davidhewitt opened this issue Nov 3, 2023 · 0 comments

Comments

@davidhewitt
Copy link
Contributor

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'))
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant