I’m writing a module to create a file for use as a resource by an Android app. As a Kotlin script I can achieve this. However, now it allegedly needs to use an Android library with a Context. (I want to call hasGlyph()
on a android.graphics.Paint
supplied with a typeface from a font resource.) I have tried "Android library," "Java or Kotlin Library," and "Phone & Tablet Module" in the Android Studio wizard, reading here, and Gradle heck. I have come to believe an app may be my only choice, but it seems terribly inconvenient to have to retrieve the file from the device (I don’t know how to do this yet either), for a task which is more of a simple script.
- Is this so unusual a situation?
- What would be the accomplishing setup?
2
Answers
A Java/Kotlin script using
java.awt.Font
for the same functionality insteadCan you share your script?
You should have no issue in creating a library like that. What you will need to do is design your API to expose the functionality you’re trying to implement.
I was unable to create an Android Library in Arctic Fox for some reason, so went to IntelliJ IDEA to put a sample together. But this is roughly what you should be looking to achieve.
If a framework function you’re needing to call requires an instance of
Context
, it may be worth thinking about if you’re requirements could be achieved without theContext
instance, and if not, can you encapsulate that kind of functionality in another class/interface.