Get the Application Package name in template Wizard recipe class Intellij


Get the Application Package name in template recipe class

  • I am working on MVVM plugin template for android studio. I completed
    most of the work.

  • But now I only need to get the application
    package name

  • Their is a method

    getPackageName(module: Module)

  • This method takes module as a input But I don’t know how to pass the module as input.

  • My core requiremnet for this task is I want to create a directory in parent directory by stand in child directory.

For example:

I have four directories A, B, C, D.

A(parent) , B ( Child of A) , C (child of B) , D (Child of C).

let say I am standing in directory D and I want to create common directory (F) inside A along with B ( F sibling to B).


You can get the parent directory form srcOut like

fun getApplicationPackageFile(srcOut: File, applicationPackage: String): File {
    var applicationPackageFile = srcOut.path.toString()
    var pk = applicationPackage.replace(".", "\\")

    val status: Boolean = applicationPackageFile.contains(pk)
    return if (status) {
        var file =
            applicationPackageFile.substring(0, applicationPackageFile.indexOf(pk)) + pk + "\\"
    } else {

And call it like

val pkFile = getApplicationPackageFile(srcOut, moduleData.projectTemplateData.applicationPackage)

So If you want to save some file to the core application package..


For Linux and Mac
Change above line to

var pk = applicationPackage.replace(".", "/")

Answered By – Taimoor Khan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published