React Native无法读取index.android.delta问题求助
解决无法读取index.android.delta的报错问题
我之前也碰到过类似的情况,这种回滚依赖后出现的缓存残留问题在React Native项目里特别常见,咱们一步步来搞定它:
1. 彻底清理React Native缓存
首先得把Metro打包器的缓存清干净,旧依赖的残留数据很可能是问题根源:
- 依次执行以下命令:
如果你的项目用Yarn管理依赖,把watchman watch-del-all rm -rf node_modules npm install rm -rf $TMPDIR/react-* npm start -- --reset-cachenpm install换成yarn install就行。
2. 清理Android构建缓存
Android端的构建缓存也可能拖后腿,进入项目的android目录,执行:
./gradlew clean
Windows用户直接运行gradlew clean就好。
3. 检查依赖残留并手动生成Bundle
- 先确认
package.json和package-lock.json(或yarn.lock)里已经完全删掉了react-native-easy-gridview的相关条目,如果lock文件还有残留,建议删掉lock文件后重新安装依赖。 - 如果前面的步骤没解决问题,可以手动生成Android的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/index.android.js,记得把命令里的index.js替换掉。
4. 重新启动项目
完成上面所有步骤后,关掉所有运行的Metro服务器和模拟器/真机,再重新执行:
react-native run-android
另外看了你提供的build.gradle配置,你的React Native版本是0.47.2,这个版本确实比较老了,虽然当前问题大概率是缓存导致,但如果后续还碰到类似奇怪的问题,也可以考虑逐步升级React Native版本来规避一些历史bug。
你的build.gradle配置参考:
apply plugin: "com.android.application" import com.android.build.OutputFile apply from: "../../node_modules/react-native/react.gradle" def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.pilbara_weed_management_mobile" minSdkVersion 16 targetSdkVersion 22 versionCode 8 versionName "1.0" ndk { abiFilters "armeabi-v7a", "x86" } } signingConfigs { release { if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) { storeFile file(MYAPP_RELEASE_STORE_FILE) storePassword MYAPP_RELEASE_STORE_PASSWORD keyAlias MYAPP_RELEASE_KEY_ALIAS keyPassword MYAPP_RELEASE_KEY_PASSWORD } } } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86" } } buildTypes { release { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" signingConfig signingConfigs.release } } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits def versionCodes = ["armeabi-v7a":1, "x86":2] 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 { compile project(':react-native-mauron85-background-geolocation') compile project(':react-native-background-task') compile project(':react-native-keep-awake') compile project(':react-native-background-timer') compile project(':react-native-image-resizer') compile project(':react-native-fcm') compile 'com.google.firebase:firebase-core:10.0.1' //this decides your firebase SDK version compile project(':react-native-fetch-blob') compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" compile ("com.facebook.react:react-native:0.47.2") { force = true } // From node_modules compile project(':react-native-smart-splashscreen') compile project(':react-native-fs') compile project(':react-native-file-opener') compile project(':react-native-camera') } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } apply plugin: 'com.google.gms.google-services'
内容的提问来源于stack exchange,提问作者Asnad Atta
相关产品推荐
相关产品推荐

