You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native CLI v0.72.5 Android构建失败:mergeExtDexDebug任务报错

React Native CLI v0.72.5 Android构建时出现viewpager2相关D8空指针错误

基于React Native CLI v0.72.5开发的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'
    }
}

app/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")

内容的提问来源于stack exchange,提问作者Azeem Idrisi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 18:05:52