Skip to content

Generates AndroidManifest.xml in simple libraries so that you don't have to

License

Notifications You must be signed in to change notification settings

GradleUp/auto-manifest

This project is archived

With Android Gradle Plugin namespaces (doc), most of the functionality provided by this plugin is now natively supported and we do not plan to support this plugin anymore.


Auto Manifest CI

AndroidManifest.xml file is crucial to define Android specific properties like minSdkVersion, uses-permission etc.

Unfortunately, package property must be defined in AndroidManifest.xml and mandatory for BuildConfig and R class generation. In most of my Gradle modules, AndroidManifest.xml is just 1 line:

<manifest package="foo" />

Here comes AutoManifest Gradle Plugin to rescue 🚀

  • This is not meant for full replacement for AndroidManifest.xml file. It is useful for those 1-liner manifests where you don't have any Activity/Service or permission defined.
  • It is easy to integrate into current projects. If manifest file is present, it will be no-op.
  • You can add it per module or to the root build.gradle. If applied to root, it will even auto generate package names based on module paths.

Configuration

Gradle Plugin Portal

Add the plugin in your build.gradle file (preferably in root one)

Kotlin
plugins {
    id("com.gradleup.auto.manifest") version "<latest-version>"
}

autoManifest {
    // Mandatory packageName
    packageName.set("com.company.example")

    // OPTIONAL //
    // Applies recursively to sub-modules so you don't have to
    // Sub-module package names will be auto generated by using their relative path
    // Default: true
    applyRecursively.set(true)
    
    // OPTIONAL //
    // Using dashes `-` is pretty common in module names. But they are not allowed within Java package names.
    // When this flag is enabled, they will be replaced by a dot. By default, they will be replaced with an underscore.
    // Default: false
    replaceDashesWithDot.set(true)
 
    //
    // Disables auto manifest generation per module (aka subproject)
    //
    // When [applyRecursively] is enabled, if you face any issues on a certain module with custom
    // setup, you can use this to disable for that module.
    // Example in a module:
    //
    // plugins {
    //   id("com.android.library")
    //   id("auto-manifest")
    // }
    // autoManifest.disable()
    //
    disable()
}
Groovy
plugins {
    id 'com.gradleup.auto.manifest' version '<latest-version>'
}

autoManifest {
    // Mandatory packageName
    packageName = 'com.company.example'

    // OPTIONAL //
    // Applies recursively to sub-modules so you don't have to
    // Sub-module package names will be auto generated by using their relative path
    // Default: true
    applyRecursively = true
 
    // OPTIONAL //
    // Using dashes `-` is pretty common in module names. But they are not allowed within Java package names.
    // When this flag is enabled, they will be replaced by a dot. By default, they will be replaced with an underscore.
    // Default: false
    replaceDashesWithDot = true
    
    //
    // Disables auto manifest generation per module (aka subproject)
    //
    // When [applyRecursively] is enabled, if you face any issues on a certain module with custom
    // setup, you can use this to disable for that module.
    // Example in a module:
    //
    // plugins {
    //   id("com.android.library")
    //   id("auto-manifest")
    // }
    // autoManifest.disable()
    //
    disable()
}

Ta-da 🎉 Now just put your Java/Kotlin files and don't worry about the rest.

Nested Modules

To make it easy for you applyRecursively is enabled by default. This will automatically generate AndroidManifest.xml for you in all modules recursively. You have 2 options to override:

  • If you need more info like permissions, Activity definitions, you can continue to have your AndroidManifest.xml and recursive generation will be skipped for that module.
  • If you need to override, you can apply the plugin again in a nested Gradle module and provide a custom packageName

Performance

  • This project uses Gradle's Lazy Task Configuration APIs and do not cause eager task creation in AGP.
  • It generates the AndroidManifest.xml file lazily. That means "zero" impact on Gradle configuration times.
  • It supports build cache so that the files are generated only once and re-used across builds.

Sample App

Checkout the sample app with multi-modules where only the Application module defines AndroidManifest.xml - available here

In Action

Here is the first integration into one of my apps: https://github.com/tasomaniac/OpenLinkWith/commit/5b4029e922c33816fde67400e6c1ac40e015c9b9

Plugin is added in couple of lines and many AndroidManifest.xml files are removed. 🎉