无法解析react-native-gesture-handler中的符号android.support.v4.util.Pools

Sob*_*ght 16 android gradle react-native

我正在从事本机项目。

通过运行“ npm install”更新模块后,

我在“ react-native-gesture-handler”的“ android.support.v4.util”中找不到类“ Pools”。

  1. 为什么会发生此错误?
  2. 我怎样才能解决这个问题?

1.错误(如果运行“ react-native run-android”)-cmd

Task :react-native-gesture-handler:compileDebugJavaWithJavac FAILED
D:\weneepl\project_y-test2_t\project_y\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:3: error: cannot find symbol
import android.support.v4.util.Pools;
                              ^
  symbol:   class Pools
  location: package android.support.v4.util
D:\weneepl\project_y-test2_t\project_y\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:19: error: package Pools does not exist
  private static final Pools.SynchronizedPool<RNGestureHandlerEvent> EVENTS_POOL =
                            ^
D:\weneepl\project_y-test2_t\project_y\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerStateChangeEvent.java:3: error: cannot find symbol
import android.support.v4.util.Pools;
                              ^
  symbol:   class Pools
  location: package android.support.v4.util
D:\weneepl\project_y-test2_t\project_y\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerStateChangeEvent.java:18: error: package Pools does not exist
  private static final Pools.SynchronizedPool<RNGestureHandlerStateChangeEvent> EVENTS_POOL =
                            ^
D:\weneepl\project_y-test2_t\project_y\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:20: error: package Pools does not exist
          new Pools.SynchronizedPool<>(TOUCH_EVENTS_POOL_SIZE);
                   ^
D:\weneepl\project_y-test2_t\project_y\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerStateChangeEvent.java:19: error: package Pools does not exist
          new Pools.SynchronizedPool<>(TOUCH_EVENTS_POOL_SIZE);
                   ^
Note:D:\weneepl\project_y-test2_t\project_y\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerButtonViewManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
Run Code Online (Sandbox Code Playgroud)

2.React本机环境信息:

System:
      OS: Windows 10
      CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
      Memory: 7.59 GB / 15.96 GB
    Binaries:
      Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
      npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: Version  3.4.0.0 AI-183.5429.30.34.5452501
Run Code Online (Sandbox Code Playgroud)

3.package.json

{
 "name": "project_y",
 "version": "0.0.1",
 "private": true,
 "scripts": {
 "start": "react-native run-android",
 "gradle-clean": "cd android & gradlew clean",
 "start-root": "react-native run-android --root",
 "test": "jest",
 "bundle": "react-native bundle --platform android --dev false --entry-file     
 index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/",
 "build": "cd android & gradlew assembleDebug"
 },
 "dependencies": {
  "axios": "^0.18.0",
  "moment": "^2.24.0",
  "prop-types": "^15.7.2",
  "react": "16.6.3",
  "react-native": "0.58.5",
  "react-native-android-open-settings": "^1.3.0",
  "react-native-custom-checkbox": "^1.5.2",
  "react-native-gesture-handler": "^1.0.16",
  "react-native-grid-list": "^1.0.9",
  "react-native-image-resizer": "^1.0.1",
  "react-native-kakao-logins": "^1.3.6",
  "react-native-linear-gradient": "^2.5.3",
  "react-native-picker-select": "^6.0.0",
  "react-native-shadow": "^1.2.2",
  "react-native-super-grid": "^3.0.3",
  "react-native-svg": "^9.2.4",
  "react-native-vector-icons": "^6.3.0",
  "react-native-webview": "^5.5.0",
  "react-navigation": "^3.3.2",
  "react-redux": "^6.0.1",
  "redux": "^4.0.1"
 },
 "devDependencies": {
  "babel-core": "7.0.0-bridge.0",
  "babel-jest": "24.1.0",
  "jest": "24.1.0",
  "metro-react-native-babel-preset": "0.52.0",
  "react-test-renderer": "16.6.3",
  "redux-devtools": "^3.5.0"
 },
 "jest": {
   "preset": "react-native"
 },
 "rnpm": {
  "assets": [
    "./assets/fonts/",
    "resources/fonts"
  ]
 }
}
Run Code Online (Sandbox Code Playgroud)

4.build.gradle(应用程序/)

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
    applicationId "com.projecty.projecty"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 10
    versionName "1.9"
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a"
    }
}
buildTypes {
    release {
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}
applicationVariants.all { variant ->
    variant.outputs.each { output ->

        def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
        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 'com.google.android.gms:play-services-base:12.0.0'
 implementation 'com.android.installreferrer:installreferrer:1.0'
 implementation 'com.igaworks.adbrix:abx-common-rm:+'

 implementation project(':react-native-webview')
 implementation project(':react-native-android-open-settings')
 implementation project(':react-native-kakao-logins')
 implementation project(':react-native-svg')
 implementation project(':react-native-linear-gradient')
 implementation project(':react-native-vector-icons')
 implementation project(':react-native-gesture-handler')

 implementation fileTree(dir: "libs", include: ["*.jar"])
 implementation "com.android.support:appcompat- 
 v7:${rootProject.ext.supportLibVersion}"
 compile(name: 'IgawSSP_v2.0.6a', ext: 'aar')
 repositories {
    flatDir {
        dirs 'libs'
    }
 }
implementation "com.facebook.react:react-native:+"  // From node_modules
}


task copyDownloadableDepsToLibs(type: Copy) {
 from configurations.compile
 into 'libs'
}

subprojects {
 repositories {
    mavenCentral()
    maven { url 
 'http://devrepo.kakao.com:8088/nexus/content/groups/public/' }
 }
}
Run Code Online (Sandbox Code Playgroud)

5.build.gradle(android /)

buildscript {
    ext {
        buildToolsVersion = "28.0.2"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'

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

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
        maven {
            url 'https://dl.bintray.com/igaworks/AdbrixRmSDK'
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        mavenCentral()
        maven {
            url 'http://devrepo.kakao.com:8088/nexus/content/groups/public/'
        }


    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}
Run Code Online (Sandbox Code Playgroud)

我希望构建项目完成。

And*_*ipe 20

我在React Native 0.60.0上遇到了同样的问题,以上答案都没有给我解决方案,所以我解决了这个问题:

npm i jetifier
npx jetify
Run Code Online (Sandbox Code Playgroud)

jetifier是npm格式的AndroidX过渡工具,具有React-Native兼容样式。

如果您将React Native模块与未转换为AndroidX的本机Java代码一起使用,而您的应用程序是AndroidX,则可能需要这样做

因此,在RN 0.60中,您需要AndroidX


pla*_*ver 17

  • 使用AndroidStudio3.3 +打开项目

AS项目

  • 点击模块android [react-native-gesture-handler]
  • 单击顶部重构->迁移到AndroidX
  • 完成了

  • 那我们不想通过androidx迁移 (2认同)

Amm*_*riq 5

Opened the project in android studio -> browse to the specified file in RNGestureHandler

remove this

import android.support.v4.util.Pools;
Run Code Online (Sandbox Code Playgroud)

And add this

import androidx.core.util.Pools;
Run Code Online (Sandbox Code Playgroud)


小智 4

类似的事情也发生在我身上。我在https://developer.android.com/reference/android/support/v4/util/Pools检查了 android 文档

  • 转到android/build.gradle

    • 依赖部分添加
      classpath "com.android.support:support-compat:28.0.0-alpha1"

这是我第一次写关于堆栈溢出的答案,我希望它是一个好的答案格式。