我正在从事本机项目。
通过运行“ npm install”更新模块后,
我找不到'react-native-gesture-handler'中'android.support.v4.util'中的'Pools'类。
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本机环境信息:
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")
}
我希望构建项目完成。
答案 0 :(得分:7)
我在React Native 0.60.0中遇到了同样的问题,以上答案都没有给我解决方案,所以我解决了这个问题:
npm i jetifier
npx jetify
jetifier是npm格式的AndroidX过渡工具,具有与本机兼容的样式。
如果您将React Native模块与非本地Java代码一起使用 转换为AndroidX,而您的应用是AndroidX,则可能需要 这个
因此,在RN 0.60中,您需要AndroidX
答案 1 :(得分:2)
答案 2 :(得分:2)
在android studio中打开了项目->浏览到RNGestureHandler中的指定文件
删除此
import android.support.v4.util.Pools;
并添加
import androidx.core.util.Pools;
答案 3 :(得分:1)
请从gradle.properties
android.useAndroidX=true
android.enableJetifier=true
答案 4 :(得分:1)
什么都没有为我工作,但是这行得通。
在enableJetifier=false
中创建gradle.properties
android.useAndroidX=true
android.enableJetifier=false
答案 5 :(得分:1)
要使其正常工作,只需添加以下两行来编辑 android>gradle.properties
文件:
android.useAndroidX=true
android.enableJetifier=true
答案 6 :(得分:0)
类似的事情发生在我身上。我在https://developer.android.com/reference/android/support/v4/util/Pools
处查看了android文档转到 android / build.gradle
classpath "com.android.support:support-compat:28.0.0-alpha1"
这是我第一次在堆栈溢出时写答案,我希望它的格式正确。
答案 7 :(得分:0)
我也面临着同样的问题。只需确保您已更新react-native-gesture-handler
的版本。如果这样做,它应该可以工作。对我来说,它是这样工作的。
答案 8 :(得分:0)
在gradle.properties
android.useAndroidX=true
android.enableJetifier=true
npm install --save-dev jetifier
或
npm install jetifier
npx jetify
npx react-native run-android
调用npx jetify
在package.json的后安装目标中运行(每当依赖项更新时,您都必须再次进行喷射)