【问题标题】:Can't resolve symbol android.support.v4.util.Pools in react-native-gesture-handler无法解析 react-native-gesture-handler 中的符号 android.support.v4.util.Pools
【发布时间】:2019-09-27 21:48:48
【问题描述】:

我正在做 react-native 项目。

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

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

  1. 为什么会出现这个错误?
  2. 我该如何解决这个问题?

1.error(如果运行“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

2.React Native 环境信息:

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

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

4.build.gradle(app/)

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/' }
 }
}

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

我希望构建项目完成。

【问题讨论】:

    标签: android react-native gradle


    【解决方案1】:

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

    npm i jetifier
    npx jetify
    

    jetifier 是一个 npm 格式的 AndroidX 过渡工具,具有 react-native 兼容风格。

    如果您将 React Native 模块与非本地 Java 代码一起使用 转换为 AndroidX,并且您的应用是 AndroidX,您可能需要 这个

    所以,在 RN 0.60 中,您需要 AndroidX

    【讨论】:

    • 在安装 react-navigation (及其所有依赖项)后,我在 0.60 时遇到了这个问题。这个解决方案解决了我的问题。
    • 也为我工作。 RN0.60
    • 不适合我现在正在抛出:package androidx.core.util does not exist
    【解决方案2】:
    • 使用AndroidStudio3.3+打开项目

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

    【讨论】:

    • 非常感谢您的回答!
    • 这可能对单个包有用,但对于需要在具有许多依赖项的 CI 环境中构建的项目没有帮助。
    • o 太好了,这应该是这个问题的正确答案。 @playSCforever 很好不要
    • 如果您对circlec有问题怎么办?我无法应用此解决方案。
    • 不想迁移到 androidx 上的我们怎么办
    【解决方案3】:

    在android studio中打开项目->在RNGestureHandler中浏览到指定文件

    删除这个

    import android.support.v4.util.Pools;
    

    然后添加这个

    import androidx.core.util.Pools;
    

    【讨论】:

      【解决方案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"

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

      【讨论】:

      • 非常适合第一个答案!我只是添加了一些格式以提高可读性
      【解决方案5】:

      请从gradle.properties中删除这两行

      android.useAndroidX=true

      android.enableJetifier=true

      【讨论】:

      • 此解决方案有效。我添加了它并修复了从 androidx 导入。谢谢
      • 此解决方案在 app/build.gradle 中添加 multidex true 后有效。 Multidex 添加参考 - stackoverflow.com/questions/52264534/…
      【解决方案6】:

      没有什么对我有用,但这有效。

      gradle.properties中创建enableJetifier=false

      android.useAndroidX=true
      android.enableJetifier=false
      

      【讨论】:

      • 我还将android.useAndroidX 设置为false,它对我有用
      【解决方案7】:

      我也面临同样的问题。只需确保您已更新 react-native-gesture-handler 的版本即可。如果你这样做,那么它应该工作。对我来说,它是这样工作的。

      【讨论】:

        【解决方案8】:

        gradle.properties中进行更改

        android.useAndroidX=true
        android.enableJetifier=true
        npm install --save-dev jetifier
        

        npm install jetifier
        npx jetify
        npx react-native run-android
        

        在你的 package.json 的 postinstall 目标中调用 npx jetify run (任何时候你的依赖更新你必须再次jetify)

        【讨论】:

          【解决方案9】:

          要使其正常工作,只需通过添加以下两行来编辑 android&gt;gradle.properties 文件:

          android.useAndroidX=true
          android.enableJetifier=true
          

          【讨论】:

            猜你喜欢
            • 2019-08-16
            • 2020-05-19
            • 1970-01-01
            • 2019-12-14
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-04-03
            相关资源
            最近更新 更多