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

我有一个本地安卓apply.当我用./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

没有它们,它就能完美地编译.因此,还有一个更大的问题,就是它无法发挥作用.两天前,所有这些库都工作正常,没有问题.但现在有什么东西把它压碎了.

推荐答案

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 "+"
            }
         }
      }
   }
}

add subprojects in build.gradle (android)

dependencies {
     ...bla bla bla

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

add implementation "com.google.android.gms:play-services-gcm:12.+" in build.gradle (android/app)

so you don't need to migrate to Androidx

编辑1:代码格式

编辑2:缺少括号

React-native相关问答推荐

在第二次加载时仅将本机应用程序设置为状态

ios 中节列表中的scrollToLocation 不起作用.在 Android 上,列表滚动回索引 0,但在 ios 上不会发生同样的情况

应用管理

React Native:如何以编程方式对图像进行黑白过滤?

如何在 React / React Native 中使用 Emscripten 编译的 JavaScript

加载作为props传递的图像

React-native android 样式化 textInput

如何在 react-native 中获取组件的大小?

命令失败:gradlew.bat installDebug error whenever installing dependencies like navigation, firebase, icons etc in React-Native

迷失在 Ionic、Cordova 等混合应用程序框架中

在 React Native 中仅显示第一行文本

我们如何将 Firebase Analytics 与基于 expo 的 react-native 应用程序一起使用

react native如何访问文件系统?

在 React Native 视图上强制 onLayout

如何在react-native矢量图标中从多个文件导入图标?

如何在 React Native 中使用 Jest

React Native:如何将文件拆分为多个文件并导入它们?

react-native:多色文本视图

React Native,更改 React Navigation 标题样式

React Native 项目,有时使用 expo start 获得连接 ECONNREFUSED 127.0.0.1:19001