react-native-vision-camera: How to fix android error, when creating custom plugin❓
Question
I been working on an example app for android using this library, which will need some native code for a frame processor plugin. I managed to make everything work with a community plugin (https://github.com/rodgomesc/vision-camera-face-detector), but now when I’m trying to create my own plugin, following the tutorial in the docs for kotlin (https://mrousavy.com/react-native-vision-camera/docs/guides/frame-processors-plugins-android) I get this error:
`
Task :app:compileDebugJavaWithJavac FAILED
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.3.3/userguide/command_line_interface.html#sec:command_line_warnings 86 actionable tasks: 80 executed, 6 up-to-date Warning: This version only understands SDK XML versions up to 2 but an SDK XML file of version 3 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times. Warning: unexpected element (uri:“”, local:“base-extension”). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level> /<BASE_DIR>/RNCamera0/android/app/src/main/java/com/rncamera0/MainApplication.java:31: error: cannot find symbol packages.add(new QRCodeFrameProcessorPluginPackage()); ^ symbol: class QRCodeFrameProcessorPluginPackage Note: /<BASE_DIR>/RNCamera0/android/app/src/debug/java/com/rncamera0/ReactNativeFlipper.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ‘:app:compileDebugJavaWithJavac’.
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 54s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 Warning: This version only understands SDK XML versions up to 2 but an SDK XML file of version 3 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times. Warning: unexpected element (uri:“”, local:“base-extension”). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level> /<BASE_DIR>/RNCamera0/android/app/src/main/java/com/rncamera0/MainApplication.java:31: error: cannot find symbol packages.add(new QRCodeFrameProcessorPluginPackage()); ^ symbol: class QRCodeFrameProcessorPluginPackage Note: /<BASE_DIR>/RNCamera0/android/app/src/debug/java/com/rncamera0/ReactNativeFlipper.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ‘:app:compileDebugJavaWithJavac’.
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 54s
at makeError (/<BASE_DIR>/RNCamera0/node_modules/execa/index.js:174:9)
at /<BASE_DIR>/RNCamera0/node_modules/execa/index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (/<BASE_DIR>/RNCamera0/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/<BASE_DIR>/RNCamera0/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details. error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
` (THIS IS THE END OF THE ERROR)
The only thing I did following the basic example I’m not sure about is, I wrote the files for the plugin and the package in the same folder as MainActivity.java, is that okay? Also I didn’t have the option to directly create a java or kotlin file, I had to click new scratch file to create both of them. (See image) I don’t know if that could be related to the fact that the directory isn’t mark in any specific way such as module or resources root.
Disclaimer: it’s my first time interacting with android native code, so it could be something really basic, I apologize in advance if that’s the case.
.
Thanks for reading and for any help any of you could give me!
What I tried
I tried following the tutorial a few times, first customizing some stuff, but then following every part including the names of the plugins and packages.
I tried I few things searching for this part of the error:
error: cannot find symbol packages.add(new QRCodeFrameProcessorPluginPackage());
But nothing worked.
VisionCamera Version
2.13.5
Additional information
- I am using Expo
- I have read the Troubleshooting Guide
- I agree to follow this project’s Code of Conduct
- I searched for similar questions in the issues page as well as in the discussions page and found none.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (5 by maintainers)
Sure, I think it is important to invest some money so I can work on this! 😃
the documentation and tutorials are assuming that you’re installing a packaged plugin from outside your project.
when you write your own local plugin, first need to declare it in
android/settings.gradle
and then add as a dependency toandroid/app/build.gradle
.first start by creating a directory located at
/android/app/src/main/java/com/rncamera0/qrcodeframeprocessor
inside that directory add your custom frame processor files:
/android/app/src/main/java/com/rncamera0/qrcodeframeprocessor/QRCodeFrameProcessorPlugin.kt
/android/app/src/main/java/com/rncamera0/qrcodeframeprocessor/QRCodeFrameProcessorPluginPackage.kt
the top line of both of those files should read:
package com.rncamera0.qrcodeframeprocessor
in your
/android/app/main/java/com/rncamera0/MainApplication.java
file, import the package:import com.rncamera0.qrcodeframeprocessor.QRCodeFrameProcessorPluginPackage
add it inside the getPackages() block:
in your
/android/settings.gradle
add these two lines afterinclude ':app'
:in your
/android/app/build.gradle
add this line to dependencies block:clean the gradle and rebuild and it should compile.