Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix React Native android build issue "package com.facebook.react.bridge does not exist"

I am getting this error:

Task :@react-native-community_async-storage:compileReleaseJavaWithJavac FAILED
/Users/Desktop/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncLocalStorageUtil.java:10: error: package javax.annotation does not exist
import javax.annotation.Nullable;                       ^
/Users/Desktop/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncLocalStorageUtil.java:20: error: package com.facebook.react.bridge does not exist
import com.facebook.react.bridge.ReadableArray;
like 1`

Why is this happening and how can I fix it?

like image 760
akhtar zaman Avatar asked May 22 '26 01:05

akhtar zaman


1 Answers

OP's solution migrated from the question to an answer:

In your android/build.gradle, add the following lines

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())

allprojects {
   configurations.all {
       resolutionStrategy {
           force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
       }
   }
}
like image 175
2 revsTylerH Avatar answered May 23 '26 13:05

2 revsTylerH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!