错误:找不到符号导入 androidx.annotation.Nullable;

Rob*_*rge 7 react-native

我安装了 Jetifier 来解决 react-native-gesture-handler 的问题,但现在我收到了这个错误:

> Task :expo-constants:compileDebugJavaWithJavac FAILED
C:\ioweu\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:\ioweu\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.
Run Code Online (Sandbox Code Playgroud)

我正在使用 React Native 和 Android Studio。我对这一切还是陌生的,所以感谢任何帮助。

这是我的依赖项:

dependencies {
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-screens')
    implementation project(':react-native-reanimated')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules

    addUnimodulesDependencies()
}
Run Code Online (Sandbox Code Playgroud)

为了解决我之前的错误,我遵循了https://github.com/facebook/react-native/issues/25483#issuecomment-508446776的内容,据我所知,它改变了我的项目以使用 AndroidX。

为了解决这两个新错误,我尝试将该行添加implementation "com.android.support:support-annotations:+"到我的 gradle.build 依赖项中,然后运行 ​​./gradlew clean 但它没有用,或者我做错了。我想我的做法是错误的。

编辑:我添加了implementation "androidx.annotation:annotation:1.1.0"但它没有解决任何问题。

编辑 2:我在这里尝试了指南:https : //flutter.dev/docs/development/packages-and-plugins/androidx-compatibility#recommended-use-android-studio-to-migrate-your-app。步骤 1、3 和 4 是唯一似乎适用于我的步骤。

这导致了以下错误:

error: package android.support.v7.app does not exist
import android.support.v7.app.AppCompatActivity;
Run Code Online (Sandbox Code Playgroud)

编辑 3:问题(与我的启动画面类)已通过添加implementation "androidx.appcompat:appcompat:1.1.0"到我的 build.gradle 并替换

> Task :expo-constants:compileDebugJavaWithJavac FAILED
C:\ioweu\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:\ioweu\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.
Run Code Online (Sandbox Code Playgroud)

dependencies {
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-screens')
    implementation project(':react-native-reanimated')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules

    addUnimodulesDependencies()
}
Run Code Online (Sandbox Code Playgroud)

我的问题现在已解决。我很抱歉提出一些问题,这些问题对更精通这一点的人来说似乎是个障碍。