-
Notifications
You must be signed in to change notification settings - Fork 151
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
Android build failed - Namespace not specified #186
Comments
To address the issue, add the following code to the CallKeep project's Gradle configuration. If you have a custom CI/CD workflow that builds the application in the cloud, you may need to fork the project and create your own version until the changes are merged into the library. |
Here is a workaround. Modify allprojects {
repositories {
...
}
// Add this:
// https://github.com/proyecto26/react-native-inappbrowser/issues/451#issuecomment-2275538714
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null || namespace.isEmpty()) {
def defaultNamespace = project.group.toString().replace('.', '_')
namespace = defaultNamespace
}
buildFeatures {
buildConfig = true
}
}
// Task to ensure namespace and remove package attribute
project.tasks.register("fixManifestsAndNamespace") {
doLast {
// Ensure namespace in build.gradle
def buildGradleFile = file("${project.projectDir}/build.gradle")
if (buildGradleFile.exists()) {
def buildGradleContent = buildGradleFile.getText('UTF-8')
def manifestFile = file("${project.projectDir}/src/main/AndroidManifest.xml")
if (manifestFile.exists()) {
def manifestContent = manifestFile.getText('UTF-8')
def packageName = manifestContent.find(/package="([^"]+)"/) { match, p -> p }
if (packageName && !buildGradleContent.contains("namespace")) {
println "Setting namespace in ${buildGradleFile}"
buildGradleContent = buildGradleContent.replaceFirst(
/android\s*\{/, "android {\n namespace '${packageName}'"
)
buildGradleFile.write(buildGradleContent, 'UTF-8')
}
}
}
// Remove package attribute from AndroidManifest.xml
def manifests = fileTree(dir: project.projectDir, includes: ['**/AndroidManifest.xml'])
manifests.each { File manifestFile ->
def manifestContent = manifestFile.getText('UTF-8')
if (manifestContent.contains('package=')) {
println "Removing package attribute from ${manifestFile}"
manifestContent = manifestContent.replaceAll(/package="[^"]*"/, '')
manifestFile.write(manifestContent, 'UTF-8')
}
}
}
}
// Ensure the task runs before the build process
project.tasks.matching { it.name.startsWith("preBuild") }.all {
dependsOn project.tasks.named("fixManifestsAndNamespace")
}
}
}
}
} |
Hi,
I try to build my project for Android. (with gradle 8.x)
Build failed with the message :
A problem occurred configuring project ':callkeep'.
any idea on how to fix it ?
The text was updated successfully, but these errors were encountered: