Changelog.md in Jepack Compose

93 Views Asked by At

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.

  1. I thought about adding changelog into assets to my settings.ui module, where I want to present - I used in setting/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.

  1. Even if I hardcoded "debug" path to assets in copy task, AssetManager does not contains changelog file. I am getting java.io.FileNotFoundException: changelog.md. My code looks like (and I aware that it should be in coroutine with Dispatcher.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?

0

There are 0 best solutions below