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

Build fails with gradle 7 #41

Closed
Andarius opened this issue Dec 18, 2021 · 6 comments · Fixed by #241
Closed

Build fails with gradle 7 #41

Andarius opened this issue Dec 18, 2021 · 6 comments · Fixed by #241
Assignees
Labels
build Build system / deployment

Comments

@Andarius
Copy link

Andarius commented Dec 18, 2021

Issue

After installing react-native-skia, npx react-native run-android fails with the following error.

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/my-project/node_modules/@shopify/react-native-skia/android/build.gradle' line: 28

* What went wrong:
A problem occurred evaluating project ':shopify_react-native-skia'.
> Plugin with id 'maven' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':shopify_react-native-skia'.
> compileSdkVersion is not specified. Please add it to build.gradle

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 5s

After some digging, I tried to make it work with this PR #43 (still failing for now).

Side note:

To build on Linux, I had to do the following before running yarn build-skia-android:

# https://docs.conda.io/en/latest/miniconda.html
conda create -n "py2" python=2
conda activate py2
pip install ninja

Then run ANDROID_NDK=$ANDROID_HOME/ndk/21.4.7075529 && yarn build-skia-android

@Andarius Andarius changed the title Build fail with gradle 7 Build fails with gradle 7 Dec 18, 2021
@chrfalch chrfalch reopened this Feb 2, 2022
@chrfalch chrfalch self-assigned this Feb 2, 2022
@Andarius
Copy link
Author

Andarius commented Feb 2, 2022

Hey @chrfalch, since you reopened this issue I updated my branch.
As I'm on Linux the build was failing because it was looking for xcrun, so I updated skia-configuration.ts accordingly.
Also since python2 is deprecated and ninja is available on python 3, I updated the command to not specify python2 anymore.

So this command succeeded: ANDROID_NDK=$ANDROID_HOME/ndk/21.4.7075529 && yarn build-skia-android using a python 3 env with ninja installed

@sultson
Copy link

sultson commented Feb 3, 2022

Hi!
I faced the same issue, but managed to make it work withGradle 7.2 by modifying @shopify/react-native-skia/android/build.gradle as such:

// android/build.gradle

// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
//   previous 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
//   previous location:
//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

// FBJNI build is based on:
// https://github.com/facebookincubator/fbjni/blob/main/docs/android_setup.md

// These defaults should reflect the SDK versions used by
// the minimum React Native version supported.
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: 'maven-publish'
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()
        }
        dependencies {
            // This should reflect the Gradle plugin version used by
            // the minimum React Native version supported.
            classpath 'com.android.tools.build:gradle:3.4.1'
        }
    }
}

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"

        externalNativeBuild {
            cmake {
                cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
                abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
                arguments '-DANDROID_STL=c++_shared'
            }
        }
    }
    lintOptions {
        abortOnError false
    }

    externalNativeBuild {
        cmake {
            path file('CMakeLists.txt')
            version '3.10.2'
        }
    }

    packagingOptions {
        excludes = ["**/libc++_shared.so"]
    }

    buildFeatures { prefab true }

    prefab {
        reactskia {
            headers "cpp/jni/include"
        }
    }

    // Create new configurations that can be referred to in dependencies.
    // The Android Gradle Plugin 3.* does not allow hooking into existing
    // configurations like `implementation`.
    configurations {
        extractHeaders
        extractJNI
    }
}

repositories {
    // ref: https://www.baeldung.com/maven-local-repository
    jcenter()
    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()
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules

    //noinspection GradleDynamicVersion
    extractHeaders("com.facebook.fbjni:fbjni:0.2.2:headers")
    //noinspection GradleDynamicVersion
    extractJNI("com.facebook.fbjni:fbjni:0.2.2")

    def rnAAR = fileTree("${rootDir}/../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
    extractJNI(files(rnAAR))
}

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.shopify.reactnative.skia"
        description packageJson.description
        url packageJson.repository.baseUrl

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

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

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)
        classpath += files(project.getConfigurations().getByName('compile').asList())
        include '**/*.java'
    }

    task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
        archiveClassifier = 'javadoc'
        from androidJavadoc.destinationDir
    }

    task androidSourcesJar(type: Jar) {
        archiveClassifier = '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
        }
    }

  
    publishing {
    publications {
            maven(MavenPublication) {
            artifact androidSourcesJar
            artifact 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
    //     }
    // }
}

task extractAARHeaders {
    doLast {
        configurations.extractHeaders.files.each {
            def file = it.absoluteFile
            copy {
                from zipTree(file)
                into "$buildDir/$file.name"
                include "**/*.h"
            }
        }
    }
}

task extractJNIFiles {
    doLast {
        configurations.extractJNI.files.each {
            def file = it.absoluteFile
            copy {
                from zipTree(file)
                into "$buildDir/$file.name"
                include "jni/**/*"
            }
        }
    }
}

tasks.whenTaskAdded { task ->
    if (task.name.contains('externalNativeBuild')) {
        task.dependsOn(extractAARHeaders)
        task.dependsOn(extractJNIFiles)
    }
}

This worked on RN 67.2 with both the debug and release builds.

@chrfalch chrfalch added the build Build system / deployment label Feb 15, 2022
@lzagar-comi
Copy link

Any news regarding this topic, I get same error on rn 0.67.2 and skia 104 build and above solution doesn't work

@a-eid
Copy link

a-eid commented Mar 8, 2022

have pretty much the same issue RN 0.67.3.

@a-eid
Copy link

a-eid commented Mar 8, 2022

Hi! I faced the same issue, but managed to make it work withGradle 7.2 by modifying @shopify/react-native-skia/android/build.gradle as such:

// android/build.gradle

// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
//   previous 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
//   previous location:
//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

// FBJNI build is based on:
// https://github.com/facebookincubator/fbjni/blob/main/docs/android_setup.md

// These defaults should reflect the SDK versions used by
// the minimum React Native version supported.
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: 'maven-publish'
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()
        }
        dependencies {
            // This should reflect the Gradle plugin version used by
            // the minimum React Native version supported.
            classpath 'com.android.tools.build:gradle:3.4.1'
        }
    }
}

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"

        externalNativeBuild {
            cmake {
                cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
                abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
                arguments '-DANDROID_STL=c++_shared'
            }
        }
    }
    lintOptions {
        abortOnError false
    }

    externalNativeBuild {
        cmake {
            path file('CMakeLists.txt')
            version '3.10.2'
        }
    }

    packagingOptions {
        excludes = ["**/libc++_shared.so"]
    }

    buildFeatures { prefab true }

    prefab {
        reactskia {
            headers "cpp/jni/include"
        }
    }

    // Create new configurations that can be referred to in dependencies.
    // The Android Gradle Plugin 3.* does not allow hooking into existing
    // configurations like `implementation`.
    configurations {
        extractHeaders
        extractJNI
    }
}

repositories {
    // ref: https://www.baeldung.com/maven-local-repository
    jcenter()
    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()
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules

    //noinspection GradleDynamicVersion
    extractHeaders("com.facebook.fbjni:fbjni:0.2.2:headers")
    //noinspection GradleDynamicVersion
    extractJNI("com.facebook.fbjni:fbjni:0.2.2")

    def rnAAR = fileTree("${rootDir}/../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
    extractJNI(files(rnAAR))
}

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.shopify.reactnative.skia"
        description packageJson.description
        url packageJson.repository.baseUrl

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

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

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)
        classpath += files(project.getConfigurations().getByName('compile').asList())
        include '**/*.java'
    }

    task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
        archiveClassifier = 'javadoc'
        from androidJavadoc.destinationDir
    }

    task androidSourcesJar(type: Jar) {
        archiveClassifier = '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
        }
    }

  
    publishing {
    publications {
            maven(MavenPublication) {
            artifact androidSourcesJar
            artifact 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
    //     }
    // }
}

task extractAARHeaders {
    doLast {
        configurations.extractHeaders.files.each {
            def file = it.absoluteFile
            copy {
                from zipTree(file)
                into "$buildDir/$file.name"
                include "**/*.h"
            }
        }
    }
}

task extractJNIFiles {
    doLast {
        configurations.extractJNI.files.each {
            def file = it.absoluteFile
            copy {
                from zipTree(file)
                into "$buildDir/$file.name"
                include "jni/**/*"
            }
        }
    }
}

tasks.whenTaskAdded { task ->
    if (task.name.contains('externalNativeBuild')) {
        task.dependsOn(extractAARHeaders)
        task.dependsOn(extractJNIFiles)
    }
}

This worked on RN 67.2 with both the debug and release builds.

would be nice if you can diff this against the original; build.gradle

@samuel-rl
Copy link
Contributor

It works for me by :

  • Commented this part (line 28) :
// apply plugin: 'maven'
  • Commented this part (line 186) :
// 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
//     }
// }
  • adding this (line 29):
apply plugin: 'maven-publish'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build system / deployment
Projects
None yet
6 participants