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 not specified #38660

Closed
priyaWedo opened this issue Jul 28, 2023 · 12 comments
Closed

Namespace not specified #38660

priyaWedo opened this issue Jul 28, 2023 · 12 comments
Labels
Resolution: Answered When the issue is resolved with a simple answer

Comments

@priyaWedo
Copy link

priyaWedo commented Jul 28, 2023

Description

I specified namespace in android>app>build.gradle , still this error is occurring ! Anyone can please help how to resolve this !

android {
ndkVersion rootProject.ext.ndk

compileSdkVersion rootProject.ext.compileSdkVersion

namespace "com.myapp"
defaultConfig {
    applicationId  "com.myapp"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
}

}

React Native Version

0.72.3

Output of npx react-native info

Screenshot 2023-07-28 at 11 04 02 AM

Steps to reproduce

when i build app in android studio Flamingo

Snack, screenshot, or link to a repository

Screenshot 2023-07-28 at 11 04 49 AM

@github-actions
Copy link

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@github-actions github-actions bot added the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Jul 28, 2023
@cortinico
Copy link
Contributor

Can you please share:

  1. your android/app/build.gradle file?
  2. the full build log

Plus having a repro would help

@priyaWedo
Copy link
Author

priyaWedo commented Aug 1, 2023

android/app/buid.gradle :

 buildscript {
   apply plugin: "com.android.application"
   apply plugin: "com.facebook.react"

apply plugin: "com.google.gms.google-services"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
apply plugin: 'com.google.firebase.crashlytics'
 
/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */
 react {
    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '..'
    // root = file("../")
    //   The folder where the react-native NPM package is. Default is ../node_modules/react-native
    // reactNativeDir = file("../node_modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
    // codegenDir = file("../node_modules/@react-native/codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
    // cliFile = file("../node_modules/react-native/cli.js")

    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]

    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
    // bundleAssetName = "MyApplication.android.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    // entryFile = file("../js/MyApplication.android.js")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []

    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]
 }

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def useIntlJsc = false

def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore (JSC)
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US. Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc-intl:+'

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    namespace "com.myapp"
  
    defaultConfig {
        applicationId  "com.myapp"
        minSdkVersion rootProject.ext.minSdkVersion
        multiDexEnabled true
        targetSdkVersion rootProject.ext.targetSdkVersion
              
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'            
        }
    }
    buildFeatures {
        buildConfig = true
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
        release {
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
     dexOptions {
    //     incremental true
    //     javaMaxHeapSize "4g"
    //     jumboMode true
      preDexLibraries = false
   }
 
    packagingOptions {
        pickFirst '**/libgnustl_shared.so'
    }

    compileOptions {
        sourceCompatibility playServicesVersion
        targetCompatibility playServicesVersion
    }
    buildToolsVersion '33.0.1'

 
}

dependencies {
     // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")
    implementation 'com.facebook.android:facebook-android-sdk:16.1.3'
    implementation("com.facebook.react:react-native:0.72.1")
    implementation("com.facebook.flipper:flipper:0.201.0")
    debugImplementation("com.facebook.flipper:flipper-network-plugin:0.201.0") {
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    implementation 'com.android.support:multidex:1.0.3'
    implementation "com.facebook.react:hermes-android"
    // implementation("com.facebook.flipper:flipper:0.201.0")
    implementation 'com.facebook.android:facebook-android-sdk:16.1.3'

    //firebase
    implementation 'com.google.firebase:firebase-analytics'
    implementation platform('com.google.firebase:firebase-bom:32.2.0')
    implementation 'com.google.firebase:firebase-auth'
    //commentted cause raising error 
    // implementation 'com.google.firebase:firebase-crashlytics'

    //for 
     if (useIntlJsc) {
        implementation 'org.webkit:android-jsc-intl:+'
    } else {
        implementation 'org.webkit:android-jsc:+'
    }
    // implementation 'com.facebook.soloader:soloader:0.9.0+'

    implementation 'com.facebook.fresco:fresco:3.0.0'
    implementation 'com.facebook.fresco:animated-gif:3.0.0'
    implementation 'com.facebook.fresco:animated-base-support:1.3.0'


    implementation project(':react-native-twilio-video-webrtc')
    // debugImplementation("com.facebook.flipper:flipper-network-plugin:0.201.0") {
    //     exclude group:'com.squareup.okhttp3', module:'okhttp'
    // }
    implementation(project(':react-native-maps')){
       exclude group: 'com.google.android.gms', module: 'play-services-base'
       exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation 'com.google.android.gms:play-services-base:17.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
   if (hermesEnabled.toBoolean()) {
       implementation("com.facebook.react:hermes-android")
   } else {
       implementation jscFlavor
   }


}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Aug 1, 2023
@cortinico cortinico added Needs: Author Feedback and removed Needs: Attention Issues where the author has responded to feedback. labels Aug 2, 2023
@cortinico
Copy link
Contributor

Please share the missing things I asked. Plus the file I asked for is android/app/build.gradle and not android/build.gradle.

@priyaWedo
Copy link
Author

@cortinico updated the file , please review it

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Aug 10, 2023
@cortinico cortinico removed the Needs: Attention Issues where the author has responded to feedback. label Aug 11, 2023
@cortinico
Copy link
Contributor

The issue is caused by one of your dependency. Sadly it's impossible to say which one, as I see you have :react-native-twilio-video-webrtc and :react-native-maps

I suspect the issue will be fixed once you bump the version of those dependencies:

Closing for now as this is not an issue in React Native itself

@priyaWedo
Copy link
Author

@cortinico thank you for your help

@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Triage 🔍 Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Aug 15, 2023
@MechLocator
Copy link

MechLocator commented Oct 31, 2023

Hi, I managed to solve this error by including the namespace in the dependencies that caused the errors. I located them from my node modules, navigated to the build.gradle file of each dependency in the android directory, and then added the namespace under the android block.

### Below is the exact solution I applied to this error for the react-native-splash-screen dependency.

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

apply plugin: 'com.android.library'

def DEFAULT_COMPILE_SDK_VERSION = 26
def DEFAULT_BUILD_TOOLS_VERSION = "26.0.2"
def DEFAULT_TARGET_SDK_VERSION = 26
def DEFAULT_SUPPORT_LIB_VERSION = "26.1.0"

android {
namespace "com.example.app" // <- add this here
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION

defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 16)
    targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
def supportLibVersion = rootProject.hasProperty('supportLibVersion') ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIB_VERSION

implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation "com.android.support:appcompat-v7:$supportLibVersion"
implementation "com.facebook.react:react-native:+" // From node_modules

}

I hope this helps someone solve this problem. If it does, that will be awesome.
PS: please follow my personal GitHub profile here: https://www.github.com/Moses-Githinji
Happy coding!!

@MechLocator
Copy link

The presentation above depicts a rookie's mistake, but I want to direct your attention to the lines below,

android {
namespace "com.example.app"
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION

defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 16)
    targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

@MechLocator
Copy link

MechLocator commented Oct 31, 2023

Make sure to replace "com.example.app" with the package name from each dependency's AndroidManifest.xml file which you should find in the "../android/src/main/AndroidManifest.xml" path.

For example, if the package name from AndroidManifest.xml is "com.sortnumbers.mathsapp", then in the dependency's build.gradle file, inside the android scope, make sure you've indicated this exactly.

android {
namespace "com.sortnumbers.mathsapp"
}

@mukesh-simform
Copy link

@cortinico By any chance is there any workaround for this issue if third-party dependencies are not having that namespace defined in their respective build gradle files?

For react native 0.73+ AGP 8+ is required and that enforces all the libraries to have namespace: react-native-community/discussions-and-proposals#671

Currently, upgrading to 0.73+ is a bit challenging because that namespace required build error is expected. Not only in this single third-party library, but build throws an error in other libraries as well.

For e.g

Screenshot 2024-06-12 at 11 58 10 AM

Manually adding namespace in gradle file of each dependencies resolves this issue, somehow this can be a patch package for few depdencies until there's an update available, but that's not feasible when application has multiple dependencies

Even following workaround is also not working. Any workaround is highly appreciated on this issue. Thank you!

android/build.gradle
--------------------

allprojects {
  ....
}

subprojects {
      afterEvaluate {
          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
                      }
                  }
              }
      }
  }

@cortinico
Copy link
Contributor

Manually adding namespace in gradle file of each dependencies resolves this issue, somehow this can be a patch package for few depdencies until there's an update available, but that's not feasible when application has multiple dependencies

Why is it not feasible with multiple dependencies?
You should reach out to those dependencies and ask them to update their libraries to conditionally add namespace in their Gradle files.

Other than this, there is nothing much we can do. We communicated this change long ago exactly to avoid scenarios like this. If you're depending on old/unmaintained libraries, I would advice to consider moving away from those dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests

4 participants