赞
踩
有的时候我们需要通过修改源码来完成某些业务需求,并上传maven仓库,以便项目的引用,这样就需要成功编译源码。
首先克隆react-native项目到本地,下载地址https://github.com/facebook/react-native
我使用的版本是0.57.7,下面是遇到的报错问题
1.NDK未配置(这里一定要用r10e版本)
- Execution failed for task ':ReactAndroid:buildReactNdkLib'.
- > Process 'command '/******/Library/Android/android-ndk-r10e/ndk-build'' finished with non-zero exit value 2
配置Android NDK 为android-ndk-r10e
什么?明明配置了还是报这个错?别急我们把系统环境变量中gradle版本修改为2.2
修改gradle/gradle-wrapper.properties中的gradle版本
- distributionBase=GRADLE_USER_HOME
- distributionPath=wrapper/dists
- zipStoreBase=GRADLE_USER_HOME
- zipStorePath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
最外层build.gradle修改gradle版本3.1.4改为1.3.1
- buildscript {
- repositories {
- mavenLocal()
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.3.1'
- classpath 'de.undercouch:gradle-download-task:3.4.3'
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
发现终于不报这个错了
2.google()方法找不到
- * Where:
- Build file '/****/react-native-0.57.7/build.gradle' line: 9
-
- * What went wrong:
- A problem occurred evaluating root project 'react-native-0.57.7'.
- > Could not find method google() for arguments [] on repository container.
那就按照提示的位置注释掉这个文件中所有google()方法,重新编译
3.子项目无法引入
- * Where:
- Build file '/****/react-native-0.57.7/ReactAndroid/build.gradle' line: 7
-
- * What went wrong:
- Error resolving plugin [id: 'com.android.library']
- > Plugin 'com.android.library' is already on the script classpath.
- Plugins on the script classpath cannot be applied in the plugins {} block.
- Add "apply plugin: 'com.android.library'" to the body of the script to use the plugin.
具体指明的是这里的代码
- plugins {
- id("com.android.library")
- id("maven")
- id("de.undercouch.download")
- }
那就统统改下
- apply plugin: 'com.android.library'
- apply plugin: 'maven'
- apply plugin: 'de.undercouch.download'
4.不推荐使用NDK?
- * Where:
- Build file '/Users/zhangdong/Downloads/react-native-0.57.7/ReactAndroid/build.gradle' line: 263
-
- * What went wrong:
- A problem occurred evaluating project ':ReactAndroid'.
- > Error: NDK integration is deprecated in the current plugin.
- Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
- Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.
按照提示在ReactAndroid中的gradle.properties文件中加入android.useDeprecatedNdk=true
5.gradle3.0一下不支持api方式引入第三方库
- * Where:
- Build file '/****/react-native-0.57.7/ReactAndroid/build.gradle' line: 300
-
- * What went wrong:
- A problem occurred evaluating project ':ReactAndroid'.
- > Could not find method api() for arguments [com.facebook.infer.annotation:infer-annotation:0.11.2] on project ':ReactAndroid'.
那就都改一下,api改为compile,testImplementation改为testCompile,androidTestImplementation改为androidTestCompile
6.找不到依赖
- * What went wrong:
- A problem occurred configuring project ':ReactAndroid'.
- > Failed to notify project evaluation listener.
- > Could not resolve all dependencies for configuration ':ReactAndroid:_debugCompile'.
- > Could not find com.android.support:appcompat-v7:27.1.1.
- Searched in the following locations:
最外层build.gradle的allprojects中添加
- maven {
- url "https://maven.google.com"
- }
7.ReactAndroid/build.gradle文件报错
- * What went wrong:
- Execution failed for task ':ReactAndroid:buildReactNdkLib'.
- > Process 'command '/Users/zhangdong/Library/Android/android-ndk-r10e/ndk-build'' finished with non-zero exit value 2
What??又是这个错,完全没有指明什么错误,查看ReactAndroid/build.gradle文件发现有些标红找不到,先注释掉,这只是一些异常捕获和编译环境的判断没有什么大碍
8.第三方库找不到对应文件
- make: *** No rule to make target `/****/react-native-0.57.7/ReactAndroid/build/third-party-ndk/glog/glog-0.3.5/src/demangle.cc',
- needed by `/****/react-native-0.57.7/ReactAndroid/build/tmp/buildReactNdkLib/local/armeabi-v7a/objs/glog/glog-0.3.5/src/demangle.o'. Stop.
- make: *** Waiting for unfinished jobs....
查看build信息貌似是缺少文件了
通过build.gradle可以看到prepareGlog这个任务就是下载glog-0.3.5.tar.gz文件并解压到build/third-party-ndk/glog中,显然没有解压成功,既然这样我们就手动解压,保证编译通过
boost_1_63_0.tar.gz,double-conversion-1.1.6.tar.gz,folly-2016.10.31.00.tar.gz同样如此
未完待续
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。