Skip to content

Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported. #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
WaseemAlBizreh opened this issue May 25, 2025 · 1 comment

Comments

@WaseemAlBizreh
Copy link

Incorrect package="com.huawei.hms.flutter.push" found in source AndroidManifest.xml: C:\Users\Lenovo\AppData\Local\Pub\Cache\hosted\pub.dev\huawei_push-6.12.0+303\android\src\main\AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="com.huawei.hms.flutter.push" from the source AndroidManifest.xml: C:\Users\Lenovo\AppData\Local\Pub\Cache\hosted\pub.dev\huawei_push-6.12.0+303\android\src\main\AndroidManifest.xml.

@WaseemAlBizreh
Copy link
Author

WaseemAlBizreh commented May 26, 2025

this works with me in android/build.gradle.kts :

allprojects {
repositories {
google()
mavenCentral()
maven("https://developer.huawei.com/repo/")
}

val targetProjects = listOf("huawei_push", "platform_device_id_plus", "google_huawei_availability")

subprojects {
    afterEvaluate {
        if (name in targetProjects && extensions.findByName("android") != null) {
            // Register the fix task only for target projects
            val fixTask = tasks.register("fixManifestsAndNamespace") {
                doLast {
                    val buildGradleFile = file("build.gradle")
                    val manifestFile = file("src/main/AndroidManifest.xml")

                    // Step 1: Set namespace from package if not already present
                    if (manifestFile.exists()) {
                        val manifestContent = manifestFile.readText(Charsets.UTF_8)
                        val packageRegex = Regex("""package\s*=\s*"([^"]+)"""")
                        val match = packageRegex.find(manifestContent)
                        val packageName = match?.groups?.get(1)?.value

                        if (packageName != null && !buildGradleFile.readText().contains("namespace")) {
                            println("Setting namespace in ${buildGradleFile.path}")
                            val updatedBuildGradle = buildGradleFile.readText().replaceFirst(
                                Regex("""android\s*\{"""),
                                "android {\n    namespace = \"$packageName\""
                            )
                            buildGradleFile.writeText(updatedBuildGradle, Charsets.UTF_8)
                        }
                    }

                    // Step 2: Remove `package` from all AndroidManifest.xml files in the project
                    val manifestFiles = fileTree("src/main") {
                        include("**/AndroidManifest.xml")
                    }

                    manifestFiles.forEach { file ->
                        val content = file.readText()
                        if (content.contains("package=")) {
                            println("Removing package attribute from ${file.path}")
                            val updated = content.replace(Regex("""package\s*=\s*"[^"]*""""), "")
                            file.writeText(updated)
                        }
                    }
                }
            }

            // Ensure the task runs before preBuild
            tasks.matching { it.name.startsWith("preBuild") }.configureEach {
                dependsOn(fixTask)
            }
        }
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant