错误日志:
- Could not get unknown property ‘mergeResourcesProvider’
RN从57.5升级到59.5,先把原先的mode_modules删干净,再npm install,完了之后,再用AndroidStudio,
build一次安卓项目,得到错误如下:(AndroidStudio中看不到其他的包)
FAILURE: Build failed with an exception.
* Where:
Script 'F:\Git\IOT\ReactNativeDe\node_modules\react-native\react.gradle' line: 95
* What went wrong:
A problem occurred configuring project ':app'.
> Could not get unknown property 'mergeResourcesProvider' for object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.
解决办法
这个问题,我是从github的issues中找到的:github—>react-native—>Issues
This not only helped me with using the latest version, but t also helped getting the vscode-react debugger back hitting breakpoints
solved by these steps:
In gradle-wrapper.properties
1.change distributionUrl to distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
2.and in root build.gradle file change gradle classpath to this: classpath 'com.android.tools.build:gradle:3.3.1'
3.Copy file 'metro.config.js' in 0.59-stable/template to your project.
4.Remove node_modules, yarn install, and run-android again.
(And make sure version of metro in package.json "metro-react-native-babel-preset": "0.51.0" is the same with current metro's version)
主要是两步,
/android/build.gradle classpath ‘com.android.tools.build:gradle:3.3.1’
/android/gradle/wrapper/grale-wrapper.properties distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
一通下载之后,第三方包安装完成;但有其他错误
2.This property has no effect, AAPT2 is now always used.
The following project options are deprecated and have been removed:
android.enableAapt2
This property has no effect, AAPT2 is now always used.
解决办法
gradle–wrapper–gradle-wrapper.properties中删除android.enableAapt2=true,该错误消失
- com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
Android resource linking failed
x:\xxx\android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
x:\xxx\android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
x:\xxx\android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3638: error: resource android:attr/fontVariationSettings not found.
x:\xxx\android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3639: error: resource android:attr/ttcIndex not found.
error: failed linking references.
解决办法
0.59的Android运行版本是28.
构建 App 的时候,打开 Build 窗口,点击 “Toggle View” 切换到文本输出。这里能看到错误的详细错误
ReBuild一次先,未解决,删掉node_modules,重新npm install一次,我使用的环境是ReactNative0.59.5,之前57版本时compileSdkVersion为27,现在要升到28才行,supportLibVersion改成28.0.0
运行后错误消失
- console.error:“React Native version mismatch”.
console.error:"React Native version mismatch".
JavaScript version:0.57.5
Native version:0.59.5
Make sure that you have rebuilt the native code.If the problem persists try clearing the Watchman and packager caches
with 'watchaman watch-del-all && react-native start --reset-cache'
看表面意思应该是要清除缓存什么的,尝试这先运行"watchaman watch-del-all && react-native start --reset-cache"
'watchaman' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
单单运行"react-native start --reset-cache",再运行"react-native run-android",运行之后,有其他问题出现
- Error: Unable to resolve module
scheduler
from
error: bundling failed: Error: Unable to resolve module `scheduler` from `F:\Git\IOT\ReactNativeDe\node_modules\react-native\Libraries\Renderer\oss\ReactNativeRenderer-prod.js`: Module `scheduler` does not exist in the Haste module map
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.
4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
at ModuleResolver.resolveDependency (F:\Git\IOT\ReactNativeDe\node_modules\@react-native-community\cli\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:183:15)
使用 npm start – --reset-cache,没用,
我没有去删除所有的node_modules,那样太慢太麻烦
我的解决办法:
找到ReactNativeRenderer-prod.js,搜索scheduler,找到var scheduler = require(“scheduler”),发现确实不存在scheduler,我按照自己的版本型号,0.59.5,重新创建了一个项目:
react-native init MyApp --version 0.59.5
运行完之后,找到scheduler,将它拷贝到我的项目中,运行成功。
升级过程中,遇到的如上五个问题。