先描述下萝卜的场景
项目是很久以前创建的Android原生项目,Android Studio 创建的
最近接入React Native模块,具体如何接入请自行查找相关资料。这里重点讲 Jenkins 打包 遇到的坑。
在Android Studio中使用 Build → Generate Signed Apk 可以正常打包。
但是在Jenkins中就各种报错。心都碎了。
不多说了,直奔重点。
第一个问题:
:app:recordFilesBeforeBundleCommandDevDebugmodule.js:471 throw err; ^ Error: Cannot find module 'D:\wwwpub\jenkins\workspace\node_modules\react-native-code-push\scripts\recordFilesBeforeBundleCommand.js' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:390:7) at startup (bootstrap_node.js:150:9) at bootstrap_node.js:505:3 FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:recordFilesBeforeBundleCommandDevDebug'. > Process 'command 'node'' finished with non-zero exit value 1 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED
解决方案:
在gradle.properties 配置中加上 nodeModulesPath 路径 (PS: 我写的是绝对路径,相对路径写了还是报错,不知道怎么写。知道的大神麻烦告诉下)
nodeModulesPath=D:/Project/WorkspaceSyt/android-v9/SYTMainLandRN/node_modules/
坑二:
:app:bundleDevReleaseJsAndAssets FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture snapshot of input files for task 'bundleDevReleaseJsAndAssets' property '$1' during up-to-date check.
> Failed to create MD5 hash for file 'D:\wwwpub\jenkins\workspace\SytAndroidV9\.gradle\3.3\taskArtifacts\taskArtifacts.lock'
.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
解决方案:
改源码的路径
文件地址:\SytAndroidV9\SYTMainLandRN\node_modules\react-native\react.gradle (PS: SytAndroidV9为Android原生工程根目录,SYTMainLandRN 为RN项目根目录)
def reactRoot = elvisFile(config.root) ?: file("../../")
改为:
def reactRoot = elvisFile(config.root) ?: file("../../SytAndroidV9/SYTMainLandRN/")
坑三:
FAILURE: Build failed with an exception.
* What went wrong:
Unable to process incoming event 'ProgressComplete ' (ProgressCompleteEvent)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
解决方案:
有人说加混淆,但是我加了之后还是报这个错误。找了另外一个方法
步骤一: 加上混淆处理
# React Native
-keep class android.text {* ;}
-dontwarn android.text.*
打包命令:
gradlew.bat assembleRelease --console plain
最后:
BUILD SUCCESSFUL
哈哈哈,到此结束