Error using React-Native-camera

Asked

Viewed 565 times

0

Hello,

I need to put the app to read the Qrcode and in the tutorial I’m finding speaks to use the React-Native-camera. I’m just not getting the camera to work.

I already made the configuration that talks on the link topic https://github.com/react-native-community/react-native-camera/blob/master/docs/installation.md#Requirements

Even so it keeps giving error and does not open the application. Follows the error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-camera:compileGeneralDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* 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

BUILD FAILED in 17s

    at checkExecSyncError (child_process.js:629:11)
    at execFileSync (child_process.js:647:13)
    at runOnAllDevices (D:\Projetos_ReactNative\Exemplos\reactnativecamera\node_modules\@r
eact-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:75
:39)
    at buildAndRun (D:\Projetos_ReactNative\Exemplos\reactnativecamera\node_modules\@react
-native-community\cli-platform-android\build\commands\runAndroid\index.js:137:41)
    at then.result (D:\Projetos_ReactNative\Exemplos\reactnativecamera\node_modules\@react
-native-community\cli-platform-android\build\commands\runAndroid\index.js:103:12)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  • What version of React-Native you are using?

  • "React": "16.8.6", "React-Native": "0.60.0",

1 answer

0

Version 0.60 is very recent (07/03/2019) so there are many libraries available that are not yet updated the documentations. A new version back the auto link function of the libraries and support for Androidx. Hence some necessary steps in the documentations are no longer useful.

Solution with downgrade

  • Open the file package.json which is in the project root folder.
  • Look for react-native": "0.60.0"
  • Change to react-native": "0.59.10" and save the file.
  • Open the terminal and run the command npm install
  • Make sure you hit it hard with the command react-native --version

Note: To keep your application with the most updated version you can use the jetifier

Solution with Jetifier

  • Install the library with the command npm install --save-dev jetifier or yarn add -D jetifier
  • Once this is done, you can run the command npx jetify which will update all dependencies to use Androidx.
  • With each installation you need to run the above command (to make it easier and not have to run the command with each new installation), we need to do one more configuration in the package.json file, adding:

    "scripts": {
        "postinstall": "npx jetify"
        ...
    } 
    

With the use of one of the methods the project must compile without problems, taking into account that all settings of the libraries are properly correct.

  • I’ll try to figure it out. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.