Skip to content
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

Namespace in AndroidManifest no longer supported #451

Open
isitcrazythough opened this issue Jan 30, 2024 · 13 comments
Open

Namespace in AndroidManifest no longer supported #451

isitcrazythough opened this issue Jan 30, 2024 · 13 comments

Comments

@isitcrazythough
Copy link

Which platform(s) does your issue occur on?

Android

Please, provide the following version numbers that your issue occurs with:

  • React native: 0.73.2
  • Inappbrowser: 3.7.0
  • gradle distribution used: 8.3-all

Please, tell us how to recreate the issue in as much detail as possible.

Compiling react native android version is impossible due to the following error:

Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported. Recommendation: remove package="com.proyecto26.inappbrowser" from the source AndroidManifest.xml.

Reproduce by having the specified react native and gradle versions and trying to run the app with the inappbrowser module. It seems that specifying the package in the android manifest instead of a build file is deprecated, so compiling apps with newer react native versions is impossible.

@isitcrazythough
Copy link
Author

Took a look at the code and it seems to be fixed in develop. Is there a reason why it's not published already, considering that the package did not receive an update for 2 years?

@isitcrazythough
Copy link
Author

Guess I'll leave it open until we get an update, considering it's quite critical.

@abramval
Copy link

abramval commented Feb 5, 2024

How can I get around this error while there are no fixes?

@isitcrazythough
Copy link
Author

I worked around this by forcing the correct namespace for all my dependencies by specifying this in android/build.gradle

subprojects {
    beforeEvaluate {
        project ->
            if (project.hasProperty("android")) {
                android {
                    def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
                    if (namespace == null && agpVersion >= 7) {
                        namespace project.group
                    }
                }
            }
    }
}

@rajdeepnanua-okta
Copy link

@jdnichollsc, could you publish a new release? I see that the fix for this has already been merged, and react-native 0.73 is unusable without the fix or a workaround.

@gabrielnascr
Copy link

any updates?

@danielyooo
Copy link

I do the namespace in the buil.gradle of the app. Just do:
namespace = "com.proyecto26.inappbrowser"
And remove the line package="com.proyecto26.inappbrowser" in the AndroidManifest

@SabriGhazali
Copy link

For me the solution it was a script before the compile to set the namespace in build.gradle and remove the package attribute from AndroidManifest.xml.

Here's the script:

allprojects {
    repositories {

        maven {
            // https://wix.github.io/Detox/docs/introduction/project-setup
            url("$rootDir/../node_modules/detox/Detox-android")
        }

    }
  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")
        }
      }
    }
  }

}

@thernandezcolon
Copy link

@SabriGhazali thank you so much for sharing, the subproject did it work for me!

@rajeevCs
Copy link

rajeevCs commented Aug 22, 2024

thanks ,works for me too

@alexanderdavide
Copy link

alexanderdavide commented Oct 10, 2024

@SabriGhazali's solution works but in my case it is important to put the allprojects block at the top with buildscript coming afterwards. Otherwise, the following error appears:

Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.

@wbjohnson
Copy link

t.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(/packa

This looks like what I've spent all day looking for! I assume it will work for Manifests in older, unsupported libraries that are declared in the pubspec?

@vladimirivanoviliev
Copy link

vladimirivanoviliev commented Feb 11, 2025

I had the same issue in new react-native project and able to fix it with setting android.enableJetifier=true in android/gradle.properties next to android.useAndroidX=true.

Edit:
Another option if you dont need the AndroidX compatibility as mentioned in the readme is to modify the android/build.gradle as follows:

androidXAnnotation = "1.2.0"
androidXBrowser = "1.3.0"

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