question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build fails with gradle 7

See original GitHub issue

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 https://github.com/Shopify/react-native-skia/pull/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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
sultsoncommented, 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.

2reactions
samuel-rlcommented, Mar 8, 2022

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'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Build fails with Gradle 7 · Issue #377 · srs/gradle-node-plugin
Reason: A property without annotation isn't considered during up-to-date checking. Possible solutions: 1. Add an input or output annotation. 2. Mark it as...
Read more >
Upgrading your build from Gradle 7.x to the latest
Upgrading your build from Gradle 7.x to the latest. version 7.6 ... Invalid specifications are deprecated and will become build errors in Gradle...
Read more >
Build failure with gradle 7+ - artifactory - Stack Overflow
I am trying to build an app using Gradle 7+, I am getting. Using insecure protocols with repositories, without explicit opt-in, ...
Read more >
Build fails with Gradle 7 : KMA-238 - YouTrack
Build fails with Gradle 7 ... Actual: build fails with: Some problems were found with the configuration of task ':iosApp:generateEditableXcodeproj' (type ' ...
Read more >
Gradle build fails with build tools 31.0.0 - Unity Forum
0. Building a gradle project throws this error: "Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found