反应原生构建错误:包android.support.annotation不存在

新手上路,请多包涵

我不得不完全重写这个问题。

我有一个反应原生的 android 应用程序。当我使用 ./gradlew assembleRelease -x bundleReleaseJsAndAssets 构建 apk 文件时,它运行良好,但之后它完全停止编译。甚至 react-native run-android 也不再工作了。

到目前为止我发现了什么:首先,错误是这样的

Task :app:processDebugResources FAILED
resource android:attr/fontVariationSettings not found.
resource android:attr/ttcIndex not found.

如果我将这些行添加到 gradle.properties

 android.useAndroidX=true
android.enableJetifier=true

错误改变。现在是这个

Task :@JWWon_react-native-universal-pedometer:compileDebugJavaWithJavac FAILED

error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
                                 ^
cannot find symbol
  private void sendPedometerUpdateEvent(@Nullable WritableMap params) {
                                         ^
  symbol:   class Nullable
  location: class BMDPedometerModule

问题不在于图书馆。如果我从项目中删除它,它就会开始抱怨另一个。为了让它编译,我必须删除 7 个库。一个例子:

 Task :@react-native-community_netinfo:compileDebugJavaWithJavac FAILED
error: package android.support.v4.net does not exist
import android.support.v4.net.ConnectivityManagerCompat;
error: cannot find symbol
    promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(getConnectivityManager()));
                    ^
  symbol:   variable ConnectivityManagerCompat
  location: class ConnectivityReceiver
2 errors

然后如果我删除另一个,就会发生这种情况:

 Task :react-native-camera-kit:compileDebugJavaWithJavac FAILED
package android.support.annotation does not exist
import android.support.annotation.ColorInt;
                                 ^
package android.support.annotation does not exist
import android.support.annotation.IntRange;
                                 ^
...
92 errors

因此,如果我从项目中删除 7 个库,它将编译。他们是:

react-native-camera-kit @react-native-community_netinfo react-native-push-notification react-native-sensors @JWWon_react-native-universal-pedometer react-native-keep-awake react-native-toast-native

没有它们,它可以完美编译。因此,有一个更大的问题无法让它发挥作用。 2 天前,所有这些库都运行良好,没有任何问题。但现在有什么东西把它压碎了。

原文由 irondsd 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.1k
2 个回答
allprojects {
  repositories {
      bla bla bla...
  }
  subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.+"
            }
            if (details.requested.group == 'com.google.android.gms'
            && !details.requested.name.contains('multidex') && !details.requested.name.contains('play-services-stats')) {
                details.useVersion "12.+"
            }
            if (details.requested.group == 'com.google.android.gms'
            && !details.requested.name.contains('multidex') && details.requested.name.contains('play-services-stats')) {
                details.useVersion "+"
            }
         }
      }
   }
}

在 build.gradle (android) 中添加子项目

dependencies {
     ...bla bla bla

    implementation "com.google.android.gms:play-services-gcm:12.+"
}

在 build.gradle (android/app) 中添加实现“com.google.android.gms:play-services-gcm:12.+”

所以你不需要迁移到 Androidx

编辑1:代码格式

编辑2:缺少括号

原文由 Mokhamad nur hidayat 发布,翻译遵循 CC BY-SA 4.0 许可协议

尝试使用喷射器

npm install --save-dev jetifier

或者使用yarn,但是在你的项目中本地安装,而不是全局安装

npx jetify

或者

npx jetify -w=1 指定并行worker的数量

npx react-native run-android

原文由 bằng đoàn 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题