简体   繁体   中英

React Native Android build failing with 'compileDebugJavaWithJavac' on several packages

I've been working in the same React Native project for months and recently the Android build has started failing. To my knowledge I haven't changed anything about my development environment and I haven't updated or changed any packages or dependencies that the project uses.

Task :@react-native-community_async-storage:compileDebugJavaWithJavac FAILED

Task :@react-native-community_datetimepicker:compileDebugJavaWithJavac FAILED

Task :@react-native-community_toolbar-android:compileDebugJavaWithJavac FAILED

Task :@sentry_react-native:compileDebugJavaWithJavac FAILED

Task :@react-native-community_netinfo:compileDebugJavaWithJavac FAILED

I've done all of the following that I found from other questions with a similar problem

  • Synced the project with gradle files in android studio
  • Ran gradlew clean in the android directory which does succeed, but the build still fails
  • Checked that android.useAndroidX and android.enableJetifier in the gradle.properties file are both true
  • Checked that I have implementation "com.facebook.react:react-native:+" in my build.gradle file. I tried changing it from + to the actual version of react native that I'm using but it made no difference.

I'm not an expert mobile developer by any means so I'm hoping that I'm missing something obvious, but any help or suggestions would be greatly appreciated.

I had been struggling with the same issue for weeks. Android build just stopped working in November. Just found the solution here (phew!) https://github.com/facebook/react-native/issues/35210

On November 4th 2022 React Native version 0.71.0-rc0 was published but this event resulted in build failures for Android on several users as they ended up downloading the wrong React Native version (0.71.0-rc0 instead of the version they were using in their project, say 0.68.0).

See all the detail in the link but the solution for me was to add the configurations.all section below to the android/build.gradle file

allprojects {
    repositories {...}
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:0.61.5"
        }
    }
}

For good measure I then also did the following

$ rm -rf node_modules
$ cd android 
$ rm -rf .gradle
$ cd ..
$ npm install
$ react-native run-android

Hope this helps someone else as I was really struggling to fix this one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM