********>npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1444 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'demo'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:3.2.1.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:3.2.1.
> Could not get resource 'https://maven.google.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
> Could not GET 'https://maven.google.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
> Connect to maven.google.com:443 [maven.google.com/172.217.27.142] failed: Connection timed out: connect
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 28s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'demo'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:3.2.1.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:3.2.1.
> Could not get resource 'https://maven.google.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
> Could not GET 'https://maven.google.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
> Connect to maven.google.com:443 [maven.google.com/172.217.27.142] failed: Connection timed out: connect
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 28s
解决方法:
*******>npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1444 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Installing the app...
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.1/userguide/command_line_interface.html#sec:command_line_warnings
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':@react-native-community_viewpager'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 35s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':@react-native-community_viewpager'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 35s
解决方法:
环境变量名称定义规范或保持一致(暂未发现除path保持一致外其他地方引用“ANDROID_HOME”)
FAILURE: Build failed with an exception.
* Where:
Script '***\node_modules\react-native\react.gradle' line: 238
* 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.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* Where:
Script '***\node_modules\react-native\react.gradle' line: 238
* 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.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
解决方法:
react-native框架中各版本不匹配问题;
参考:
https://blog.csdn.net/gongxiaoou/article/details/81082387
https://developer.android.google.cn/studio/releases/gradle-plugin
https://blog.csdn.net/qq_29507011/article/details/114124420
http://www.blogdaren.com/post-2418.html
https://blog.csdn.net/hejisan/article/details/81533836
例如可行的版本:
修改/android/build.gradle文件,下面一行的版本号
classpath ‘com.android.tools.build:gradle:3.3.0’
修改/android/gradle/wrapper/grale-wrapper.properties文件,下面一行的版本号
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.1-all.zip
* What went wrong:
java.io.IOException: Unable to delete directory ***\node_modules\@react-native-community\viewpager\android\build\generated\source\buildConfig\debug\com\reactnativecommunity.
> Unable to delete directory ***\node_modules\@react-native-community\viewpager\android\build\generated\source\buildConfig\debug\com\reactnativecommunity.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9m 33s
3 actionable tasks: 3 executed
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
Command failed: gradlew.bat installDebug
解决方法:
Unable to delete directory 或者 Failed to create directory: 等类似问题
清除缓存
cd android && gradlew clean && cd .. && react-native run-android
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':@react-native-community_viewpager:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
10 actionable tasks: 1 executed, 9 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
解决方法:
参考:https://blog.csdn.net/Cui_xing_tian/article/details/103401791
注入插件
npm i jetifier
npx jetify
6、
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0-rc01] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 19s
117 actionable tasks: 115 executed, 2 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
解决方法:
7、NodeJS新版本启动Metro服务器报错
错误原因
在百度上搜索此错误,大部分都是提及新版本不兼容旧版本导致的,需要回退nodejs版本的,但是Windows上又没法进行NodeJS版本回退,也找不到旧的NodeJS版本进行安装。
偶然间翻到一个解决办法,上面提到了这个问题是一个版本兼容的bug,官方链接是:
https://github.com/facebook/metro/pull/464/commits/7d0464836890163c02790f1bf4d8550a34fb95a3,
点击链接可以查看到具体的原因是因为新版本修改了sharedBlacklist正则表达式导致旧版本不能匹配而导致的bug。
SyntaxError: Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class
at new RegExp (
at blacklist (D:\workspace-work-idea\pdnms-app-front\node_modules\metro-config\src\defaults\blacklist.js:34:10)
at getBlacklistRE (D:\workspace-work-idea\pdnms-app-front\node_modules\react-native\local-cli\util\Config.js:56:10)
at Object.
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Module._compile (D:\workspace-work-idea\pdnms-app-front\node_modules\pirates\lib\index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Object.newLoader [as .js] (D:\workspace-work-idea\pdnms-app-front\node_modules\pirates\lib\index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
解决办法
所以解决办法就是修改node_modules\metro-config\src\defaults\blacklist.js,将文件内原有的/node_modules[/\\]react[/\\]dist[/\\].*/, 修改为/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
8、启动成功后,均未发现问题,但是真机测试就是存在一片空白无任何反应,不是白屏问题,可能是node版本过高,与RN版本不匹配造成的,需降低node版本
如:node 14.xx 与RN0.58.xx 不匹配;将node降为12.22.xx则正常
9、
再有问题建议删除代码重新clone或者重建项目;
再回头看原来上述的问题是多么苍白,不晓得为啥蹦出来这么多问题;
重新加载项目全部正常,共勉~~~