Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
304 stars 80 forks source link

Failed to build with Gradle 7 #124

Closed k3-cat closed 2 years ago

k3-cat commented 2 years ago

Description

Failed to build app with react-native-tcp-socket using Gradle 7 and corresponding Gradle Plugin.

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a new react native project
  2. Changing the version of Gradle Wrapper to 7.0.2 with
  3. Scroll down to '....'
  4. See error

Or code:

// gradle-wrapper.properties (distributionUrl)
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip

// build.gradle (buildscript)
buildscript {
    ext {
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "21.4.7075529"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.0.1")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

Current behavior

Unable to build the app.

Expected behavior

Able to build the app with react-native-tcp-socket using Gradle 7 -- as react-native and other packages (such as react-native-screens react-native-gesture-handler react-native-get-random-values .etc) already supports Gradle 7 with corresponding Gradle Plugin.

Screenshots

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\x-rk\Source\VibSensor\node_modules\react-native-tcp-socket\android\build.gradle' line: 24

* What went wrong:
A problem occurred evaluating project ':react-native-tcp-socket'.
> 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 ':react-native-tcp-socket'.
> com.android.builder.errors.EvalIssueException: 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.
==============================================================================

Relevant information

OS Windows 11 22449.1000
react-native 0.65.1
react-native-tcp-socket 5.3.0

NOTE: https://docs.gradle.org/7.0/userguide/upgrading_version_6.html

Reuben-BeaconTech commented 2 years ago

I have the same issue here. Any idea of a fix/workaround? I have an app update to release but this is blocking the build.

k3-cat commented 2 years ago

I have the same issue here. Any idea of a fix/workaround? I have an app update to release but this is blocking the build.

I think we have to wait the author to update the build.gradle file. Something like replace maven with maven-publish, rewrite tasks, and update the version of gradle plugin version.

Rapsssito commented 2 years ago

@Pix-00 and @Reuben-BeaconTech, I am working on it. I will release a fix ASAP.

k3-cat commented 2 years ago

@Pix-00 and @Reuben-BeaconTech, I am working on it. I will release a fix ASAP.

Tanks very much.

Rapsssito commented 2 years ago

@Pix-00, could you test if changing the gradle.build file in node_modules/react-native-tcp-socket/android to the following fixes your issue:

apply plugin: 'com.android.library'

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

android {
  compileSdkVersion safeExtGet('compileSdkVersion', 29)

  defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 21)
    targetSdkVersion safeExtGet('targetSdkVersion', 29)
  }
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules
}
k3-cat commented 2 years ago

@Rapsssito Yes, it works. Thanks a lot ヾ(≧▽≦*)o.

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 5.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: