首页 > 解决方案 > React Native 0.60.5 - 构建时任务:expo-constants:compileDebugJavaWithJavac FAILED

问题描述

我创建了一个新的 React Native 应用程序并将所有内容升级到最新版本(React Native、组件、Gradle),但在尝试构建和部署到设备时出现以下错误) - 这是 VS Code 终端中的输出:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\myAppFolder\MyApp\MyApp> react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1187 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :app
...
.../*more debugging progress output here*/..
...
ace
 unimodules-sensors-interface@3.0.0 from C:\myAppFolder\MyApp\MyApp\node_modules\unimodules-sensors-interface
 unimodules-task-manager-interface@3.0.0 from C:\myAppFolder\MyApp\MyApp\node_modules\unimodules-task-manager-interface

> Task :expo-constants:compileDebugJavaWithJavac

> Task :expo-constants:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.6.1/userguide/command_line_interface.html#sec:command_line_warnings
84 actionable tasks: 1 executed, 83 up-to-date
C:\MyAppFolder\MyApp\MyApp\node_modules\expo-constants\android\src\main\java\expo\modules\constants\ConstantsService.java:6: error: cannot find symbol
import androidx.annotation.Nullable;
                          ^
  symbol:   class Nullable
  location: package androidx.annotation
C:\MyAppFolder\MyApp\MyApp\node_modules\expo-constants\android\src\main\java\expo\modules\constants\ConstantsService.java:51: error: cannot find symbol
  @Nullable
   ^
  symbol:   class Nullable
  location: class ConstantsService
2 errors

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':expo-constants: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 6m 2s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
C:\MyAppFolder\MyApp\MyApp\node_modules\expo-constants\android\src\main\java\expo\modules\constants\ConstantsService.java:6: error: cannot find symbol
import androidx.annotation.Nullable;
                          ^
  symbol:   class Nullable
  location: package androidx.annotation
C:\MyAppFolder\MyApp\MyApp\node_modules\expo-constants\android\src\main\java\expo\modules\constants\ConstantsService.java:51: error: cannot find symbol
  @Nullable
   ^
  symbol:   class Nullable
  location: class ConstantsService
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':expo-constants: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 6m 2s

    at checkExecSyncError (child_process.js:616:11)
    at execFileSync (child_process.js:634:15)
    at runOnAllDevices (C:\MyAppFolder\MyApp\MyAPp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:74:39)
    at buildAndRun (C:\MyAppFolder\MyApp\MyAPp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:158:41)
    at C:\MyAppFolder\MyApp\MyAPp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:125:12
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
    at async Command.handleAction (C:\MyAppFolder\MyApp\MyApp\node_modules\react-native\node_modules\@react-native-community\cli\build\cliEntry.js:160:7)

我已尝试将以下内容添加到 ./android/gradle.properties 以确保该项目,但这似乎会导致其他类型的问题

android.useAndroidX=true
android.enableJetifier=true

这是我的 package.json

{
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.6.1",
    "expo": "^34.0.4",
    "react": "16.9.0",
    "react-dom": "^16.9.0",
    "react-native": "0.60.5",
    "react-native-elements": "^1.2.0",
    "react-native-gesture-handler": "~1.4.1",
    "react-native-reanimated": "~1.2.0",
    "react-native-unimodules": "~0.5.4",
    "react-native-vector-icons": "^6.6.0",
    "react-native-web": "^0.11.7",
    "react-navigation": "^4.0.0",
    "react-navigation-tabs": "^2.4.0"
  },
  "devDependencies": {
    "@babel/core": "^7.5.5",
    "babel-jest": "24.9.0",
    "jest": "24.9.0",
    "jetifier": "^1.6.4",
    "metro-react-native-babel-preset": "0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  },
  "private": true
}

Jetifier(将所有非本地 Android 模块迁移到 AndroidX) - 似乎是建议的解决方案,但我有这个解决方案(Jetifier 在构建时自动运行 - 如上所示)并且没有帮助。

任何建议,将不胜感激。

标签: androidreact-nativegradleandroidx

解决方案


推荐阅读