Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

react_native_pytorch_core error during gradle build #213

Open
yMayanand opened this issue May 1, 2023 · 15 comments
Open

react_native_pytorch_core error during gradle build #213

yMayanand opened this issue May 1, 2023 · 15 comments

Comments

@yMayanand
Copy link

Version

No response

Problem Area

react-native-pytorch-core (core package)

Steps to Reproduce

No response

Expected Results

No response

Code example, screenshot, or link to repository

WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.

[stderr] 
FAILURE: Build failed with an exception.

[stderr] 
* Where:

[stderr] 
Build file '/home/expo/workingdir/build/node_modules/react-native-pytorch-core/android/build.gradle' line: 132

[stderr] 
* What went wrong:

[stderr] 
A problem occurred evaluating project ':react-native-pytorch-core'.

[stderr] 
> Expected directory '/home/expo/workingdir/build/android/../node_modules/react-native/android' to contain exactly one file, however, it contains no files.

[stderr] 
* Try:

[stderr] 
> Run with --stacktrace option to get the stack trace.

[stderr] 
> Run with --info or --debug option to get more log output.

[stderr] 
> Run with --scan to get full insights.

[stderr] 
* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings

5 actionable tasks: 5 executed

[stderr] 
BUILD FAILED in 2m 22s

Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
@yMayanand yMayanand changed the title I am trying to generate apk file from expo eas build but i am getting following error during gradle build. How should i solve this error? react_native_pytorch_core error during gradle build May 1, 2023
@TommiHonkanen
Copy link

I am also getting this same error no matter if I create a new project and add react-native-pytorch-core or try to add it to an existing project. I am using react native version 0.71.6 and pytorch core version 0.2.4.

lahna@Acer-Nitro-5:~/Desktop/playtorch/pytorch-test/test-app$ npm run android

WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.

FAILURE: Build failed with an exception.

* Where:
Build file '/home/lahna/Desktop/playtorch/pytorch-test/test-app/node_modules/react-native-pytorch-core/android/build.gradle' line: 132

* What went wrong:
A problem occurred evaluating project ':react-native-pytorch-core'.
> Expected directory '/home/lahna/Desktop/playtorch/pytorch-test/test-app/android/../node_modules/react-native/android' to contain exactly one file, however, it contains no files.

* 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.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 10s
5 actionable tasks: 4 executed, 1 from cache
Error: /home/lahna/Desktop/playtorch/pytorch-test/test-app/android/gradlew exited with non-zero code: 1

@SpyGuy0215
Copy link

Same here, I am also getting this issue with a clean app with only react-native-pytorch-core installed. Any updates?

@yMayanand
Copy link
Author

Same here, I am also getting this issue with a clean app with only react-native-pytorch-core installed. Any updates?

Not yet, its very frustrating to get any pytorch model into android app using react-native. Hoping this problem to be fixed with future releases.

@SpyGuy0215
Copy link

Is there any fix for now? I kinda need this

@TommiHonkanen
Copy link

I think react-native-pytorch-core doesn't support react native 0.71 yet. I created an app with react native version 0.70 and didn't get this error,

@yMayanand
Copy link
Author

Is there any fix for now? I kinda need this

For demo purpose you can run the project using expo and playtorch app on ios or android device.

@QuinceyJames
Copy link

It looks like react native intentionally remove the contents of the android folder to reduce their package size. Please see react-native-community/discussions-and-proposals#508

@yMayanand
Copy link
Author

which version of pytorch-core you were working with?

@PierreLepagnol
Copy link

PierreLepagnol commented May 17, 2023

Hi, I got the same error for expo sdk version 48, but not for sdk 47.
Here is my package.json :

{
  "name": "test",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "expo": "~47.0.14",
    "expo-status-bar": "~1.4.2",
    "react": "18.1.0",
    "react-native": "0.70.8",
    "react-native-pytorch-core": "^0.2.4",
    "expo-splash-screen": "~0.17.5"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}

Try with this and tell me !

@yMayanand
Copy link
Author

when did you run the project laslty with the above configuration, because i am getting the same error everytime not matter which configuration i am running with.

@PierreLepagnol
Copy link

I immediately posted this message after launching 😊

Perhaps, test it whith a fresh blank app ?

@yMayanand
Copy link
Author

I immediately posted this message after launching blush

Perhaps, test it whith a fresh blank app ?

yeah you were right its working with the configuration that you have suggested. Although it was a blank app but if you have any functional app than it throws Execution failed for task ':app:mergeDebugNativeLibs'. error. But there is a workaround suggested on playtorch website all we have to do is add following code in build.gradle file in android folder of app.

    // ...

    /**
     * Without the packaging options, it will result in the following build error:
     *
     * * What went wrong:
     * Execution failed for task ':app:mergeDebugNativeLibs'.
     * > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
     *    > More than one file was found with OS independent path 'lib/x86/libfbjni.so'
     */
    packagingOptions {
        pickFirst '**/*.so'
    }
    sourceSets {
        main {
            jniLibs.srcDirs += ["$buildDir/extra-jniLibs/jni"]
        }
    }
    configurations {
        extraJNILibs
    }

    // ...
}

dependencies {
    // ...

    // Used to control the version of libfbjni.so packaged into the APK
    extraJNILibs("com.facebook.fbjni:fbjni:0.2.2")

    // ...
}

// ...

// Extract JNI shared libraries as project libraries. This assumes the target directory, $buildDir/extra-jniLibs, is added to the jniLibs.srcDirs configuration.
task extraJNILibs {
  doLast {
    configurations.extraJNILibs.files.each {
      def file = it.absoluteFile

      copy {
        from zipTree(file)
        into "$buildDir/extra-jniLibs" // temp location instead of "src/main/jniLibs"
        include "jni/**/*"
      }
    }
  }
}

tasks.whenTaskAdded { task ->
  if (task.name == 'mergeDebugJniLibFolders' || task.name == 'mergeReleaseJniLibFolders') {
    task.dependsOn(extraJNILibs)
  }
}

// ...```
Reference link: "https://playtorch.dev/docs/tutorials/add-package/"

@TheEndurance
Copy link

I immediately posted this message after launching blush
Perhaps, test it whith a fresh blank app ?

yeah you were right its working with the configuration that you have suggested. Although it was a blank app but if you have any functional app than it throws Execution failed for task ':app:mergeDebugNativeLibs'. error. But there is a workaround suggested on playtorch website all we have to do is add following code in build.gradle file in android folder of app.

    // ...

    /**
     * Without the packaging options, it will result in the following build error:
     *
     * * What went wrong:
     * Execution failed for task ':app:mergeDebugNativeLibs'.
     * > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
     *    > More than one file was found with OS independent path 'lib/x86/libfbjni.so'
     */
    packagingOptions {
        pickFirst '**/*.so'
    }
    sourceSets {
        main {
            jniLibs.srcDirs += ["$buildDir/extra-jniLibs/jni"]
        }
    }
    configurations {
        extraJNILibs
    }

    // ...
}

dependencies {
    // ...

    // Used to control the version of libfbjni.so packaged into the APK
    extraJNILibs("com.facebook.fbjni:fbjni:0.2.2")

    // ...
}

// ...

// Extract JNI shared libraries as project libraries. This assumes the target directory, $buildDir/extra-jniLibs, is added to the jniLibs.srcDirs configuration.
task extraJNILibs {
  doLast {
    configurations.extraJNILibs.files.each {
      def file = it.absoluteFile

      copy {
        from zipTree(file)
        into "$buildDir/extra-jniLibs" // temp location instead of "src/main/jniLibs"
        include "jni/**/*"
      }
    }
  }
}

tasks.whenTaskAdded { task ->
  if (task.name == 'mergeDebugJniLibFolders' || task.name == 'mergeReleaseJniLibFolders') {
    task.dependsOn(extraJNILibs)
  }
}

// ...```
Reference link: "https://playtorch.dev/docs/tutorials/add-package/"

I am a tad confused, so do I need to use a lower version of expo, react and react-native , AND also manually change the build.gradle files?

@yMayanand
Copy link
Author

yes need to use lower version and manually add the changes in gradle file because i found only this thing to be working.

@CarolinaRMarques
Copy link

Due to work-related issues, I, for example, cannot downgrade RN, when will the release for newer RN versions happen? Is this being planned?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants