DEV Community

Cover image for How to specify an alternative location for the AndroidManifest.xml
👨‍💻Ioannis Diamantidis
👨‍💻Ioannis Diamantidis

Posted on • Originally published at diamantidis.github.io

1

How to specify an alternative location for the AndroidManifest.xml

By default, Gradle expects an AndroidManifest.xml file on the root directory of the main source set of every Android project. But what if for some reason we want to change this?

For me, one such case is the default Kotlin Native project. When creating a new project, the template creates a few source sets for the common, the iOS, and the Android implementation. For the common and the iOS source sets, it uses names like commonMain and iOSMain. But when it comes to the Android source set, the name is not the expected androidMain but rather a plain main.

As I wanted to keep a consistent and more clear naming for the source sets, I decided to rename the name of the folder main to androidMain. And that's when the problem appeared. When I tried to build the app, I got an error saying "Cannot read packageName from src/main/AndroidManifest.xml".

The good news are that we have the option to change this location on the build.gradle!

Inside the android block, we can set manifest.srcFile to the new location of the AndroidManifest.xml.

sourceSets {
    main {
        manifest.srcFile 'src/androidMain/AndroidManifest.xml'
        java.srcDirs = ['src/androidMain/java']
        res.srcDirs = ['src/androidMain/res']
    }
}
Enter fullscreen mode Exit fullscreen mode

And voilĂ !!
Gradle uses the AndroidManifest.xml inside the androidMain folder and we are now able to build and run the app again!


➡️ This post was originally published on my blog.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay