react-native-static-server icon indicating copy to clipboard operation
react-native-static-server copied to clipboard

Compilation error with gradle 7 and react native latest version 0.69

Open Uma19 opened this issue 3 years ago • 5 comments

After upgrading my project android to latest version of gradle 7 , this package is throwing following error

  • What went wrong: A problem occurred evaluating project ':react-native-static-server'. > Plugin with id 'maven' not found.

As of Gradle and Andriod team, gradle 7 onwards will support maven-pulbish plugin So is there any plan to fix the above project ?

Uma19 avatar Jul 08 '22 09:07 Uma19

@Uma19 do you fixed? can you share how you fixed the error?

thanhnvpk01168 avatar Jul 09 '22 10:07 thanhnvpk01168

We are able to solve temporary by replacing the content of node_modules/react-native-static-server/build.gradle to:

// android/build.gradle

// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
//   original location:
//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
//   original location:
//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

buildscript {
    // The Android Gradle plugin is only required when opening the android folder stand-alone.
    // This avoids unnecessary downloads and potential conflicts when the library is included as a
    // module dependency in an application project.
    // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
    if (project == rootProject) {
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.4.1'
        }
    }
}

plugins {
    id('com.android.library')
    id('maven-publish')
}

def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28

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

//apply plugin: 'com.android.library'
//apply plugin: 'maven'



//apply plugin: 'com.android.library'
//apply plugin: 'maven'

android {
    compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
    buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
        targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
}

repositories {
    // ref: https://www.baeldung.com/maven-local-repository
    mavenLocal()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven {
        // Android JSC is installed from npm
        url "$rootDir/../node_modules/jsc-android/dist"
    }
    google()
    jcenter()
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules
    implementation 'org.nanohttpd:nanohttpd:2.3.1'
    implementation 'org.nanohttpd:nanohttpd-webserver:2.3.1'
}

def configureReactNativePom(def pom) {
    def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

    pom.project {
        name packageJson.title
        artifactId packageJson.name
        version = packageJson.version
        group = "com.futurepress.staticserver"
        description packageJson.description
        url packageJson.repository.baseUrl

        licenses {
            license {
                name packageJson.license
                url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
                distribution 'repo'
            }
        }

        developers {
            developer {
                id packageJson.author.username
                name packageJson.author.name
            }
        }
    }
}

//afterEvaluate { project ->
//    // some Gradle build hooks ref:
//    // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
//    task androidJavadoc(type: Javadoc) {
//        source = android.sourceSets.main.java.srcDirs
//        classpath += files(android.bootClasspath)
//        project.getConfigurations().getByName('implementation').setCanBeResolved(true)
//        classpath += files(project.getConfigurations().getByName('implementation').asList())
//        include '**/*.java'
//    }
//
//    task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
//        classifier = 'javadoc'
//        from androidJavadoc.destinationDir
//    }
//
//    task androidSourcesJar(type: Jar) {
//        classifier = 'sources'
//        from android.sourceSets.main.java.srcDirs
//        include '**/*.java'
//    }
//
//    android.libraryVariants.all { variant ->
//        def name = variant.name.capitalize()
//        def javaCompileTask = variant.javaCompileProvider.get()
//
//        task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
//            from javaCompileTask.destinationDir
//        }
//    }
//
//    artifacts {
//        archives androidSourcesJar
//        archives androidJavadocJar
//    }
//
//    task installArchives(type: Upload) {
//        configuration = configurations.archives
////        repositories.mavenDeployer {
////            // Deploy to react-native-event-bridge/maven, ready to publish to npm
////            repository url: "file://${projectDir}/../android/maven"
////            configureReactNativePom pom
////        }
//
//        repositories {
//            maven {
//                url = "file://${projectDir}/../android/maven"
//                configureReactNativePom pom
//            }
//        }
//    }
//
//
//}

But we are now looking to remove this library from our project.

douglasjunior avatar Jul 12 '22 20:07 douglasjunior

Hi @douglasjunior , Thank you so much for your answer. it worked fine on my side. Can u tell me please which package u switch to from react-native-static-server ?

malik-coachhub avatar Sep 28 '22 09:09 malik-coachhub

Hi @douglasjunior , Thank you so much for your answer. it worked fine on my side. Can u tell me please which package u switch to from react-native-static-server ?

Today this library is used in the project to display HTML pages in WebView, we are moving towards removing this architecture and starting to use only native screens.

douglasjunior avatar Sep 29 '22 12:09 douglasjunior