environment: Mac Os
I am playing around with expo-projects and pure react-native projects. For a long time I did only use expo. Now I just wanted to try a pure react-native project created by:
react-native init AwesomeProject cd AwesomeProject react-native run-android
then I get these kind of errors:
FAILURE: Build failed with an exception. * What went wrong: Could not resolve all files for configuration ':app:debugCompileClasspath'. > Could not find expolib_v1.com.facebook.infer.annotation:infer-annotation:0.11.2. Required by: project :app > com.facebook.react:react-native:32.0.0 > Could not find expolib_v1.com.squareup.okhttp3:okhttp:3.6.0. Required by: project :app > com.facebook.react:react-native:32.0.0 > Could not find expolib_v1.com.squareup.okio:okio:1.13.0. Required by: project :app > com.facebook.react:react-native:32.0.0 > Could not find expolib_v1.com.squareup.okhttp3:okhttp-urlconnection:3.6.0. Required by: project :app > com.facebook.react:react-native:32.0.0 > Could not find expolib_v1.com.facebook.fresco:expolib_v1-imagepipeline-okhttp3:1.0.1. Required by: project :app > com.facebook.react:react-native:32.0.0
Then I started investigations. What went wrong? My first conclusion was “The pure react-native-project uses an expo-react-native version. Why?”.
Finally I solved the problem by deleting the local maven cache by
rm -Rf $HOME/.m2/.repository
It seems that
- gradle looks into
android/app/build.gradlethere it finds the instruction
- so gradle tries to get the latest react-native-version
- then gradle searches first the local maven directory in
- there gradle finds the expo-react-native version 32.0.0 (from a previous expo-eject-project) and installs it
- so the pure react-native project installs the wrong version
So when I removed $HOME/.m2/.repository, then gradle does not find the locally cached version, then it downloads the latest official pure react-native version from the web-repositories.
Another solution would be to set the exact version in
android/app/build.gradle. This would look like this (get latest Version info from official react-native-website):
// before check the exact version in the top-level-folder of your project in package.json implementation "com.facebook.react:react-native:0.59.5"
I hope this helps others
Best regards from the Austrian Mountains