Kureev / react-native-blur

React Native Blur component
MIT License
3.76k stars 556 forks source link

Android app: Namespace not specified. Please specify a namespace in the module's build.gradle file like so: #592

Open aihoque2 opened 1 year ago

aihoque2 commented 1 year ago

updating my react-native app from 0.69.5 to 0.72.1. However, when I try to build with npx react-native run-android or do a ./gradlew clean I get this bug:

A problem occurred configuring project ':@react-native-community_blur'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Please specify a namespace in the module's build.gradle file like so:

     android {
         namespace 'com.example.namespace'
     }

here's my android/app/build.gradle:

apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js",
    enableHermes: true,  // clean and rebuild if changing
    bundleInDebug: false,
    bundleInStaging: true,
    bundleInRelease: true,
    devDisabledInDebug: false,
    devDisabledInStaging: true,
    devDisabledInRelease: true,
    jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
    resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
    jsBundleDirStaging: "$buildDir/intermediates/assets/staging",
    resourcesDirStaging: 
        "$buildDir/intermediates/res/merged/staging",
    jsBundleDirRelease: "$buildDir/intermediates/assets/release",
    resourcesDirRelease: 
        "$buildDir/intermediates/res/merged/release",
]

def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", true);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    namespace 'com.someApptest'

    if (project.android.hasProperty("namespace")) {
         namespace(android.namespace)
    }

    defaultConfig {
        applicationId "com.someApp.test"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 69
        versionName "ayoo"
        multiDexEnabled true

        ndk {
           abiFilters "armeabi-v7a", "arm64-v8a"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false 
            include "armeabi-v7a", "arm64-v8a"
        }
    }
    signingConfigs {
        release {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }

    packagingOptions {
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
    }

    buildTypes {
        debug {
            applicationIdSuffix ".dev"
        }
        staging {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            applicationIdSuffix ".test"

            matchingFallbacks = ['release']
        }
        release {

            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"

        }
    }
    applicationVariants.all { variant ->
        variant.outputs.each { output ->

            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {                  output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }
}

dependencies {
    implementation project(':react-native-restart')
    implementation project(':react-native-fast-image')
    implementation project(':react-native-reanimated')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-video')
    implementation "androidx.appcompat:appcompat:1.0.0"
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+" // From node_modules
    implementation project(':react-native-fs')
    implementation "no.nordicsemi.android:dfu:2.0.1"
    implementation("com.facebook.react:react-android")

    if (enableHermes) {
       implementation("com.facebook.react:hermes-android") {
           exclude group:'com.facebook.fbjni'
       }
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.implementation
    into 'libs'
}

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

How do specify the namespace in my android/app/build.gradle?

thommedia commented 1 year ago

Any update on this? I have the same issue.

SERCHAT commented 12 months ago

I have already this issue please help!

L0rdCr1s commented 11 months ago

@SERCHAT just go to the library build.gradle and add namespace 'your_namespace' and the error will go away.

SERCHAT commented 11 months ago

Thank you @L0rdCr1s. Because I use a lot of packages which are not using namespace in theirs build.gradle files I 'am looking for a gradle script who do this job. For this library only your recommendation worked perfectly thank you again.