react-native-vision-camera: 🐛 Can not build for android - Could not find fbjni-0.5.0-headers.jar

What were you trying to do?

Without changing anything during the last few days, now out of a sudden, the build doesn’t work. I get the some errors regarding maven.

Reproduceable Code

I stuck in the build time

What happened instead?

Unable to build

Relevant log output

* What went wrong:
Execution failed for task ':react-native-vision-camera:extractAARHeaders'.
> Could not resolve all files for configuration ':react-native-vision-camera:extractHeaders'.
   > Could not find fbjni-0.5.0-headers.jar (com.facebook.fbjni:fbjni:0.5.0).
     Searched in the following locations:
         https://repo.maven.apache.org/maven2/com/facebook/fbjni/fbjni/0.5.0/fbjni-0.5.0-headers.jar

Device

Android 11

VisionCamera Version

2.13.3 (also tested the latest version)

Additional information

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 10
  • Comments: 19 (3 by maintainers)

Most upvoted comments

If you change these two lines in node_modules/react-native-vision-camera/android/build.gradle

//noinspection GradleDynamicVersion
extractHeaders("com.facebook.fbjni:fbjni:0.4.0:headers")
//noinspection GradleDynamicVersion
extractJNI("com.facebook.fbjni:fbjni:0.4.0")

you can build your project successfully

I have raised a PR to this repo which changes the import of fbjni to explicitly define version 4 as the dependency. This should really be the case anyway, to save this scenario from happening in the future.

#1666

You can use patch-package to keep the changes around, but it will bloat your VCS a bit.

@carolinaknoll thanks for the clarification. I noticed the 0.5.1 update had been published. If your builds still don’t work it may be a caching issue. Worth busting the gradle caches
 or run something like ./gradlew assembleDebug --refresh-dependencies << worked for me.

@domthomhive I’ve also been reading through the issue in fbjni’s own thread. From what I understand, when the owner released v0.5.0, he forgot to add the headers. So you can have a react native project that has the following lines, either on android/app/build.gradle or inside a dependency like node_modules/<dependency_name>/app/build.gradle.

//noinspection GradleDynamicVersion
 extractHeaders("com.facebook.fbjni:fbjni:+:headers")
 //noinspection GradleDynamicVersion
 extractJNI("com.facebook.fbjni:fbjni:+")

These lines make it so that these projects can get the latest version of fbjni automatically, since they don’t assign a particular version of fbjni to use. However, as v0.5.0 doesn’t have the headers, the project build fails because of it.

The owner has released v0.5.1 which has the headers. But as @fendorio said, this this same issue can happen in the future, because again, there are these lines of code saying “get the latest version automatically, regardless if it is available/has everything it needs or not”.

Strangely, I thought that by using these lines we would start to get v0.5.1 automatically so that the error would go away and the projects would build correctly again, which doesn’t seem to be the case. My project is still failing to build, as one of it’s dependencies is still looking for v0.5.0 and not v0.5.1. đŸ€”

Ultimately, I agree that we can use patch-package to fix this issue without waiting for more changes.

It’s great that a fix has been deployed upstream, however, this library should still be patched to explicitly define the dependency version, as to avoid the same situation occurring again.

If you change these two lines in node_modules/react-native-vision-camera/android/build.gradle

//noinspection GradleDynamicVersion
extractHeaders("com.facebook.fbjni:fbjni:0.4.0:headers")
//noinspection GradleDynamicVersion
extractJNI("com.facebook.fbjni:fbjni:0.4.0")

you can build your project successfully

It worked. As of now, version 0.5.0 of fbjni-java is not available.

I added this section in the android/build.gradle file, It’s a slightly cleaner approach.

project('react-native-vision-camera') {
    configurations.all {
        resolutionStrategy {
            force "com.facebook.fbjni:fbjni:0.4.0"
        }
    }
}

If you change these two lines in node_modules/react-native-vision-camera/android/build.gradle

//noinspection GradleDynamicVersion
extractHeaders("com.facebook.fbjni:fbjni:0.4.0:headers")
//noinspection GradleDynamicVersion
extractJNI("com.facebook.fbjni:fbjni:0.4.0")

you can build your project successfully

It worked. Ty man.

fbjni estĂĄ lançando um 0.5.1 com cabeçalho para corrigir isso ( facebookincubator/fbjni#85 (comentĂĄrio) ), mas eles tĂȘm um comentĂĄrio preocupante sobre a compatibilidade do NDK ( facebookincubator/fbjni#85 (comentĂĄrio) ). NĂŁo deveria react-native-vision-cameradeixar de especificar “qualquer” versĂŁo (+)?

0.5.1 will be hitting Maven Central in the next minutes.

We’ll follow up with more guidance on how to patch the affected libraries in the near future

here it’s back to normal

I only tried to alter the extractJNI, didn’t think to also change extractHeaders. Thanks. đŸ‘đŸ»

I guess fbjni 0.5.0 is breaking (allowed by semantic version change) but this library does not specify a correct version range.

 if (REACT_NATIVE_VERSION < 71) {
      //noinspection GradleDynamicVersion
      extractHeaders("com.facebook.fbjni:fbjni:+:headers")
      //noinspection GradleDynamicVersion
      extractJNI("com.facebook.fbjni:fbjni:+")

https://github.com/mrousavy/react-native-vision-camera/blob/3ed019d018cce9ff20afb0fcc81146732419f17e/android/build.gradle#L291C1-L295C47