numandev1 / react-native-compressor

🗜️Compress Image, Video, and Audio same like Whatsapp 🚀✨
MIT License
949 stars 93 forks source link

error Failed build android #318

Open ahmedhango opened 6 days ago

ahmedhango commented 6 days ago

Current behavior

React Native Version

72.4

React Native Compressor Version

1.9.0

Reproducible Steps And Demo

github-actions[bot] commented 6 days ago

👋 @ahmedhango Thanks for opening your issue here! If you find this package useful hit the star🌟!

ahmedhango commented 6 days ago

android build .gradle // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript { ext { buildToolsVersion = "34.0.0" minSdkVersion = 29 compileSdkVersion = 34 targetSdkVersion = 34 // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. ndkVersion = "26.1.10909125" kotlinVersion = "1.9.22" playServicesLocationVersion = "21.0.1" }

repositories {
    google()
    mavenCentral()
    maven { url 'https://jitpack.io' }
}
dependencies {
    classpath 'com.google.gms:google-services:4.4.1'
    classpath 'com.android.tools.build:gradle:7.4.2'
    classpath("com.facebook.react:react-native-gradle-plugin")

}

} subprojects { afterEvaluate { project -> if (project.hasProperty('android')) { project.android { if (namespace == null) { namespace "com.nupconeer" } } } // 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")
    }
}

}