从git上导入公司的项目,在本地运行的时候,项目无法运行。sdk,jdk,node都是使用公司规定的版本,项目中的local.properties文件sdk.dir路径也换成了自己本地的目录,结果就在react-native run-Android的时候,卡着了,等了一个多小时,报错结果如下:
> Task :jpush-react-native:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
158 actionable tasks: 22 executed, 136 up-to-date
D:\test\app-prd2 (1)\app-prd2 (1)\app\node_modules\jpush-react-native\android\src\main\java\cn\jiguang\plugins\push\JPushModule.java:387: ����: �Ҳ�������
JSONObject notificationExtraJson = new JSONObject(notificationExtra.toHashMap());
^
����: ���� toHashMap()
λ��: ����ΪReadableMap�ı��� notificationExtra
D:\test\app-prd2 (1)\app-prd2 (1)\app\node_modules\jpush-react-native\android\src\main\java\cn\jiguang\plugins\push\JPushPackage.java:13: ����: JPushPackage���dz����, ����δ����ReactPackage�еij���createJSModules()
public class JPushPackage implements ReactPackage {
^
2 ������
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jpush-react-native:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
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 17s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
D:\test\app-prd2 (1)\app-prd2 (1)\app\node_modules\jpush-react-native\android\src\main\java\cn\jiguang\plugins\push\JPushModule.java:387: ����: �Ҳ�������
出现乱码不用管,一开始觉得是gradle下不下来,就去修改了gradle-wrapper.properties的distributionUrl,改成本地的gradle,结果还是可住一个多小时,卡后报一样的错误。如果有人因为gradle下不下来,可以移步到这个博客:
https://blog.csdn.net/lbb17745169396/article/details/79064394?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242
由于运行卡在:
Resolve dependencies of :app:debugRuntimeClasspath > maven-metadata.xml
想着可能是因为下载依赖的时候,配置的是国外的远程仓库,所以下不下来,所以就去build.gradle文件修改的mavenURL,由于不知道是哪个mavenURL连不上,所以我就把四个URL都改成了阿里的镜像:
maven { url "https://maven.aliyun.com/repository/google"}
maven { url "https://maven.aliyun.com/repository/public" }
maven { url "https://maven.aliyun.com/repository/jcenter" }
maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
配置好之后运行,这次没有卡了,又报了一个错,错误如下:
> Task :app:validateSigningDebug FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
383 actionable tasks: 2 executed, 381 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:validateSigningDebug'.
> Keystore file 'D:\test\app-prd2 (1)\app-prd2 (1)\app\android\app\hglife.keystore' not found for signing config 'debug'.
* 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 22s
这次报错原因倒是简单,看“* What went wrong: ”下面的提示:
Keystore file 'D:\test\app-prd2 (1)\app-prd2 (1)\app\android\app\hglife.keystore' not found for signing config 'debug'.
就是说我的android\app目录下没有hglife.keystore文件,这个文件是Android平台签名证书,要么禁用,要么问公司要一个或者生成(一般的项目hglife.keystore都是自定义的,生成无法直接使用),禁用移步百度。要到文件直接,react-native run-Android后项目就运行起来了。
后面自己也总结,特别是运行卡住哪里,我把报原来的mavenURL注释关掉,然后逐一注释四个URL。
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
// // ADD THIS
//原配置
maven { url 'https://www.jitpack.io' }
maven { url 'https://maven.google.com' }
等到我把 maven { url 'https://maven.google.com' }这个URL注释掉,其他三个都打开,项目运行没有卡掉,而是运行报错,我就明白的,是 maven { url 'https://maven.google.com' }这个URL无法连接,把这个换成阿里的镜像地址之后,项目运行的时候没有卡了。
结语:
项目重导运行报错,错误原因主要有:
- 运行环境不支持(jkd,sdk等)
- 无法下载配置(科学上网或者使用国内镜像)
- 缺少文件(有些文件证书或者加密文件只有在项目上线才提供,提交到仓库文件会被忽略而导致无法运行)