React Native:错误包android.support.annotation不存在

React Native:错误包android.support.annotation不存在,android,react-native,Android,React Native,错误是由 任务:反应本机摄影机:编译器GeneralReleaseJavaWithJavaC失败 这些错误略有不同,但都有指向不存在的包的插入符号。之后还有大约100个非常相似的地方: 我有一个RN v0.57项目需要更新,以便继续播放商店,在尝试直接升级后,我开始看到谷歌从未见过的错误,因此我选择在我的src文件夹和相关package.json数据上创建一个新项目和端口 我想用这种方式修复所有错误可能需要一周的时间,而不是根据过去的经验,我希望用一个月的时间来处理升级带来的错误。我已经修复了

错误是由

任务:反应本机摄影机:编译器GeneralReleaseJavaWithJavaC失败

这些错误略有不同,但都有指向不存在的包的插入符号。之后还有大约100个非常相似的地方:

我有一个RN v0.57项目需要更新,以便继续播放商店,在尝试直接升级后,我开始看到谷歌从未见过的错误,因此我选择在我的src文件夹和相关package.json数据上创建一个新项目和端口

我想用这种方式修复所有错误可能需要一周的时间,而不是根据过去的经验,我希望用一个月的时间来处理升级带来的错误。我已经修复了十几个早期的bug,然后才被困在这个bug上,所以我不能确定那里的补丁没有引入这个bug,但是这样想会让你毫无进展,所以我发现自己在这里

我已经读了一些关于androidx的文章,或者与此相关,或者是可能的修复,但是我最不想做的就是开始介绍可能出错的新东西。代码库很好,在0.57中运行,我只想将其升级到最新版本,在商店中发布,再也不看react native了

这是my package.json:

{
  "name": "(Projectname)",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@babel/runtime": "^7.1.2",
    "@react-native-community/cli-platform-android": "^2.9.0",
    "@svgr/core": "^4.2.0",
    "axios": "^0.18.0",
    "date-fns": "^1.30.1",
    "link": "^0.1.5",
    "moment": "^2.24.0",
    "pod-installer": "0.0.0",
    "qs": "^6.5.2",
    "react": "16.9.0",
    "react-moment": "^0.8.4",
    "react-native": "0.61.4",
    "react-native-action-picker": "^1.0.2",
    "react-native-action-sheet": "^2.2.0",
    "react-native-android-log": "^1.1.0",
    "react-native-button": "^2.3.0",
    "react-native-cached-image": "^1.4.3",
    "react-native-calendar-picker": "^6.0.0",
    "react-native-camera": "^2.11.0",
    "react-native-communications": "^2.2.1",
    "react-native-date-picker": "^2.3.0",
    "react-native-document-picker": "^2.1.0",
    "react-native-fetch-blob": "^0.10.8",
    "react-native-fit-image": "^1.5.4",
    "react-native-fontawesome": "^6.0.1",
    "react-native-fs": "^2.13.2",
    "react-native-gesture-handler": "^1.0.17",
    "react-native-image-crop-picker": "^0.22.0",
    "react-native-lazyload-deux": "^2.0.4",
    "react-native-photo-editor": "^1.0.0",
    "react-native-responsive-grid": "^0.41.992",
    "react-native-router-flux": "^4.0.0-beta.31",
    "react-native-simple-toast": "0.0.8",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^9.3.7",
    "react-native-tab-view": "0.0.74",
    "react-native-web-swiper": "^1.15.1",
    "react-navigation": "^3.3.0",
    "react-navigation-stack": "^1.0.10",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0",
    "semver": "^6.0.0",
    "uuid": "^3.3.2"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "babel-core": "^7.0.0-bridge.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.47.0",
    "react-native-svg-transformer": "^0.12.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  },
  "rnpm": {
    "assets": [
      "./src/fonts"
    ]
  }
}
我的Android\app\build.gradle:

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.projectname"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        missingDimensionStrategy 'react-native-camera', 'general' (this was a fix I found and tried but hasn't helped)
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "com.google.android.gms:play-services-gcm:12.+" 
    implementation 'com.android.support:appcompat-v7:28.0.0'
    androidTestImplementation "com.android.support:support-annotations:28.0.0"

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
还有我的Android\build.gradle,我添加的任何与谷歌服务相关的东西都试图修复这个bug,但没有帮助:

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        googlePlayServicesVersion = "16.+"
        firebaseVersion = "17.3.4"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.2")
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
    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.requested.name.contains('play-services-vision-image-label') ||
                    !details.requested.name.contains('play-services-clearcut') ||
                    !details.requested.name.contains('play-services-flags') ||
                    !details.requested.name.contains('play-services-phenotype')
                    )) {
                    details.useVersion "12.+"
                }
                if (details.requested.group == 'com.google.android.gms'
                && !details.requested.name.contains('multidex') && (
                    details.requested.name.contains('play-services-stats') ||
                    details.requested.name.contains('play-services-vision-image-label') ||
                    details.requested.name.contains('play-services-clearcut') ||
                    details.requested.name.contains('play-services-flags') ||
                    details.requested.name.contains('play-services-phenotype')
                    )) {
                    details.useVersion "+"
                }
                if (details.requested.group == 'com.google.firebase'
                && !details.requested.name.contains('multidex') && details.requested.name.contains('firebase-messaging')) {
                    details.useVersion "12.+"
                }
            }
        }
    }
}

ext {
    googlePlayServicesVersion = "+" // default: "+"
    firebaseVersion = "+" // default: "+"
    // Other settings
    compileSdkVersion = 28 // default: 23
    buildToolsVersion = "28.0.3" // default: "23.0.1"
    targetSdkVersion = 28 // default: 23
    supportLibVersion = "28.0.0"
}

如果您能提供任何帮助或建议,我们将不胜感激。最终目标是将我正在工作的RN v0.57应用程序安装到应用商店中,我正试图将我的应用程序移植到一个新的init'd RN项目中,以便实现这一点,因此如果您知道一种更简单的方法,我很乐意采用这一方法。据我所知,没有快速的“补丁”,我可以应用到0.57,使其为游戏商店所接受,并且考虑到我过去在RN中遇到的任何版本更改问题,我认为直接从0.57升级将更加困难。

您可以看到这个问题的答案()@Lenoarod我确实切换到了androidx,现在我有了几乎相同的错误,除了“错误:找不到符号导入androidx.appcompat.app.AppcompatActivity;”我使用了jetifier,它应该更新我插件中的所有引用,以使用androidx而不是旧库,但看起来有一个更深层次的问题可能会影响旧库和新库?我很高兴lost@Lenoarod哦,天哪,我的androidx导入在AppCompatActivity中有一个较低的compat大小写,修复了这个问题,让我转到了某种新的基于DexArchive的错误。你能显示一些错误信息吗,我还没有遇到你的情况更新反应本机问题,你可以看到这个站点()