Search code examples
pythonandroidpython-3.xandroid-jetpack-composechaquopy

Creating Compose elements with Chaquopy


I want to bring a plugin environment for my Kotlin Android app and I thought of using Chaquopy to easily have then written and bundled with my app.

Now I'm thinking is a good idea that plugins could also create new buttons and do things in python side when that button was pressed, or create new Texts, lists etc.

The issue I have now is that I can't import compostable methods in python side since Chaquopy doesn't support this.

Is there an workaround to do this? Maybe using reflection methods from java in python?


Solution

  • I've managed to do it but a little different.

    Instead of using compose items I used android layouts in combination with a dynamic layout loader and an axml library to convert my XML to axml binary format at runtime.

    I've made a class that initializes the dynamic layout container and a method that gets called from python with the XML as a String arguments then it gets converted to axml and passes through the dynamic layout generation code then it returns the layout back to python so it can add logic and returns it back to a AndroidView compose item to render it.

    https://github.com/gvaish/android-dynamic-layouts/blob/master/dynamic-layout-loader/src/main/java/com/yahoo/android/dlayout/LayoutLoader.java

    https://github.com/apk-editor/aXML