I would like to present a changelog in Jetpack Compose composable.
I decided to manually write it in Markdown and write it in project root folder as myproj/CHANGELOG.md
Then I used jeziellago/compose-markdown to create composable with parsed Markdown. When I paste a content from file into String in Kotlin, all works fine - app shows a dialog with Markdown() composable with parsed String.
But I have a few issues with middle steps - how to provide the file into APK and how to read it to String.
- I thought about adding changelog into assets to my
settings.uimodule, where I want to present - I used insetting/ui/build.gradle.kts
android {
tasks.register<Copy>("copyAssets") {
from("${project.rootDir}/changelog.md")
into("${buildDir}/intermediates/assets/debug")
}
tasks.named("preBuild") {
dependsOn("copyAssets")
}
}
I had to hardcoded debug subpath, because I could not find a way to dynamically put a buildType (debug or release) there.
- Even if I hardcoded "debug" path to assets in copy task,
AssetManagerdoes not contains changelog file. I am gettingjava.io.FileNotFoundException: changelog.md. My code looks like (and I aware that it should be in coroutine withDispatcher.IO;) ):
@Composable
fun ChangelogDialog(
modifier: Modifier = Modifier,
onDismiss: () -> Unit,
) {
val assetManager = LocalContext.current.assets
val changelogInputStream = assetManager.open("changelog.md")
val reader = BufferedReader(InputStreamReader(changelogInputStream))
// ...
// rest of reading the file and showing Dialog
Am I using wrong path in AssetManager or is it related with the build and fix from previous point should resolve this issue too?