突然间,我的 React Native CLI 应用程序在为 Android 构建时开始抛出此错误:
ERROR: /home/azeem-idrisi/.gradle/caches/transforms-3/46cd5fcfa0d4f80ceee4e56498bf55f5/transformed/jetified-viewpager2-1.1.0-runtime.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
FAILURE: Build failed with an exception.
* What went wrong:
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform viewpager2-1.1.0.aar (androidx.viewpager2:viewpager2:1.1.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for DexingNoClasspathTransform: /home/azeem-idrisi/.gradle/caches/transforms-3/46cd5fcfa0d4f80ceee4e56498bf55f5/transformed/jetified-viewpager2-1.1.0-runtime.jar.
> Error while dexing.
运行
./gradlew clean
成功完成。
此错误在 Windows 11、Ubuntu 和 Fedora 上仍然存在,但在 macOS 上运行良好 - 即使 2014 款 MacBook Air 以及 M1 机器也可以构建它。
我尝试过使用 Java 17 和 21。我还全新安装了 Windows,删除了
node_modules/
文件夹,并尝试了所有建议的修复,例如启用 multiDexEnabled true
。然而问题依然存在。
我的package.json:
{
"name": "SekeronApp",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.19.3",
"@react-native-camera-roll/camera-roll": "^5.10.0",
"@react-native-clipboard/clipboard": "^1.14.1",
"@react-native-community/blur": "^4.3.2",
"@react-native-community/datetimepicker": "^7.6.0",
"@react-native-community/geolocation": "^3.1.0",
"@react-native-community/netinfo": "^11.2.1",
"@react-native-community/slider": "^4.4.3",
"@react-native-firebase/app": "^20.4.0",
"@react-native-firebase/messaging": "^20.4.0",
"@react-native-google-signin/google-signin": "^10.1.2",
"@react-native-masked-view/masked-view": "^0.3.0",
"@react-navigation/bottom-tabs": "^6.5.9",
"@react-navigation/material-bottom-tabs": "^6.2.17",
"@react-navigation/material-top-tabs": "^6.6.4",
"@react-navigation/native": "^6.1.8",
"@react-navigation/native-stack": "^6.9.14",
"@reduxjs/toolkit": "^1.9.7",
"@rneui/base": "^4.0.0-rc.7",
"@rneui/themed": "^4.0.0-rc.8",
"@svanboxel/visibility-sensor-react-native": "^1.0.2",
"apisauce": "^3.0.1",
"axios": "^1.7.4",
"date-fns": "^3.6.0",
"fbjs": "^3.0.5",
"formik": "^2.2.9",
"i": "^0.3.7",
"jetifier": "^2.0.0",
"lottie-react-native": "^6.7.2",
"macaddress": "^0.5.3",
"mirrorfly-uikit-react-native": "^1.4.6",
"moment": "^2.29.4",
"npm": "^10.8.1",
"patch-package": "^8.0.0",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-audio-recorder-player": "^3.5.3",
"react-native-autoheight-webview": "^1.6.5",
"react-native-background-timer": "^2.4.1",
"react-native-calendars": "^1.1293.0",
"react-native-canvas": "^0.1.40",
"react-native-circular-progress-indicator": "^4.4.2",
"react-native-cn-quill": "^0.7.17",
"react-native-collapsible-tab-view": "^4.5.2",
"react-native-compressor": "^1.8.23",
"react-native-confirmation-code-field": "^7.3.1",
"react-native-convert-ph-asset": "^1.0.3",
"react-native-create-thumbnail": "^2.0.0",
"react-native-date-picker": "^5.0.4",
"react-native-device-info": "^11.1.0",
"react-native-document-picker": "^9.1.1",
"react-native-draggable-flatlist": "^4.0.0",
"react-native-dropdown-select-list": "^2.0.5",
"react-native-element-dropdown": "^2.5.0",
"react-native-element-textinput": "^2.0.1",
"react-native-encrypted-storage": "^4.0.3",
"react-native-fast-image": "^8.6.3",
"react-native-fbsdk-next": "^7.2.0",
"react-native-file-viewer": "^2.1.5",
"react-native-fs": "^2.20.0",
"react-native-geocoding": "^0.5.0",
"react-native-gesture-handler": "^2.12.1",
"react-native-get-random-values": "^1.10.0",
"react-native-haptic-feedback": "^2.3.3",
"react-native-heic-converter": "^1.3.3",
"react-native-image-crop-picker": "^0.41.2",
"react-native-image-picker": "^7.0.0",
"react-native-image-viewing": "^0.2.2",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-linear-gradient": "^2.8.3",
"react-native-maps": "^0.31.1",
"react-native-modal": "^13.0.1",
"react-native-modal-datetime-picker": "^14.0.1",
"react-native-modal-dropdown": "^1.0.2",
"react-native-mov-to-mp4": "^0.2.2",
"react-native-multiple-select": "^0.5.12",
"react-native-network-info": "^5.2.1",
"react-native-pager-view": "^6.1.2",
"react-native-paper": "^5.1.0",
"react-native-pell-rich-editor": "^1.8.8",
"react-native-permissions": "^4.1.5",
"react-native-popup-menu": "^0.16.1",
"react-native-progress": "^5.0.0",
"react-native-reanimated": "3.8",
"react-native-redash": "^18.1.0",
"react-native-render-html": "^6.3.4",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^3.18.2",
"react-native-select-dropdown": "^3.2.1",
"react-native-share": "^10.2.1",
"react-native-shimmer-placeholder": "^2.0.9",
"react-native-slider": "^0.11.0",
"react-native-slider-color-picker": "^2.2.3",
"react-native-splash-screen": "^3.3.0",
"react-native-step-indicator": "^1.0.3",
"react-native-svg": "^13.8.0",
"react-native-swipe-list-view": "^3.2.9",
"react-native-swiper": "^1.6.0",
"react-native-swiper-flatlist": "^3.2.3",
"react-native-tab-view": "^3.3.4",
"react-native-text-gradient": "^0.1.7",
"react-native-uuid": "^2.0.1",
"react-native-vector-icons": "^10.0.0",
"react-native-video": "^5.2.1",
"react-native-view-shot": "^3.8.0",
"react-native-virtualized-view": "^1.0.0",
"react-native-walkthrough-tooltip": "^1.4.0",
"react-native-webrtc": "^118.0.5",
"react-native-webview": "^11.26.0",
"react-redux": "^8.1.3",
"realm": "^11.9.0",
"reanimated-color-picker": "^1.0.4",
"redux-persist": "^6.0.0",
"redux-saga": "^1.2.3",
"rn-fetch-blob": "^0.12.0",
"tinycolor2": "^1.5.2",
"yup": "^0.32.11"
},
"reactNativePermissionsIOS": [
"AppTrackingTransparency",
"BluetoothPeripheral",
"Calendars",
"Camera",
"Contacts",
"FaceID",
"LocationAccuracy",
"LocationAlways",
"LocationWhenInUse",
"MediaLibrary",
"Microphone",
"Motion",
"Notifications",
"PhotoLibrary",
"PhotoLibraryAddOnly",
"Reminders",
"Siri",
"SpeechRecognition",
"StoreKit"
],
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native-community/eslint-config": "^2.0.0",
"@react-native/eslint-config": "^0.72.2",
"@react-native/metro-config": "^0.72.11",
"@tsconfig/react-native": "^3.0.0",
"@types/jsdom": "^20.0.1",
"@types/node": "^18.11.14",
"@types/react": "^18.0.24",
"@types/react-native-datepicker": "^1.7.1",
"@types/react-native-fbsdk": "^3.0.2",
"@types/react-native-html-to-pdf": "^0.8.1",
"@types/react-native-htmlview": "^0.16.0",
"@types/react-native-video": "^5.0.14",
"@types/react-test-renderer": "^18.0.0",
"@types/tinycolor2": "^1.4.3",
"babel-jest": "^29.2.1",
"babel-plugin-module-resolver": "^5.0.0",
"deprecated-react-native-prop-types": "^2.3.0",
"eslint": "^8.19.0",
"jest": "^29.2.1",
"metro-react-native-babel-preset": "0.76.8",
"mirrorfly-reactnative-sdk": "^1.0.17",
"prettier": "^2.4.1",
"react-test-renderer": "18.2.0",
"typescript": "4.8.4"
},
"engines": {
"node": ">=16"
}
}
我的build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 24
compileSdkVersion = 34
targetSdkVersion = 33
// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "25.1.8937393"
googlePlayServicesAuthVersion = "20.7.0"
}
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath 'com.google.gms:google-services:4.4.0'
}
}
我的应用程序/build.gradle:
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
apply plugin: 'com.google.gms.google-services'
react {
}
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
namespace "com.sekeronapp"
defaultConfig {
applicationId "com.sekeronapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
implementation("com.facebook.react:react-android")
implementation(platform("com.google.firebase:firebase-bom:33.3.0"))
implementation("com.google.firebase:firebase-analytics")
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
通过安装最新版本的
react-native-pager-view
解决了这个问题,该版本被其他一些包用作内部依赖项。