首页 > 解决方案 > React Native:错误包android.support.annotation不存在

问题描述

错误是由

任务:react-native-camera:compileGeneralReleaseJavaWithJavac FAILED

这些错误略有不同,但都有指向一个不存在的包的插入符号。在它之后还有大约 100 个非常相似: 在此处输入图像描述 在此处输入图像描述

我有一个 RN v0.57 项目需要更新才能进入 Play 商店,在尝试直接升级后,我开始看到谷歌以前从未见过的错误,所以我选择创建一个新项目并移植到我的src 文件夹和相关的 package.json 数据。

根据过去的经验,我认为可能需要一周的时间来修复所有错误,而不是我期望的一个月来追踪升级引入的错误。在被困在这个之前,我已经修复了大约十几个早期的错误,所以我不能确定那里的修复没有引入这个,但是这样想会让你没有任何进展,所以我在这里找到了自己。

我已经阅读了一些有关 androidx 的信息,或者与此相关或可能的修复,但我想做的最后一件事是开始引入可能出错的新事物。代码库很好,并且在 0.57 中工作,我只想将它升级到最新版本,在商店中获取它,并且永远不会再看 react native。

这是我的 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,我添加的任何与谷歌服务相关的东西都试图修复这个错误,但它没有帮助:

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 以使其被 Play 商店接受,并且直接从 0.57 升级我相信考虑到我在任何版本更改中遇到的问题会更加困难过去在注册护士。

标签: androidreact-native

解决方案


推荐阅读