当前位置:   article > 正文

ReactNative: 编译源码项目_plugin 'com.android.library' is already on the scr

plugin 'com.android.library' is already on the script classpath

有的时候我们需要通过修改源码来完成某些业务需求,并上传maven仓库,以便项目的引用,这样就需要成功编译源码。

首先克隆react-native项目到本地,下载地址https://github.com/facebook/react-native

我使用的版本是0.57.7,下面是遇到的报错问题

1.NDK未配置(这里一定要用r10e版本)

  1. Execution failed for task ':ReactAndroid:buildReactNdkLib'.
  2. > 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版本

  1. distributionBase=GRADLE_USER_HOME
  2. distributionPath=wrapper/dists
  3. zipStoreBase=GRADLE_USER_HOME
  4. zipStorePath=wrapper/dists
  5. distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip

最外层build.gradle修改gradle版本3.1.4改为1.3.1

  1. buildscript {
  2. repositories {
  3. mavenLocal()
  4. jcenter()
  5. }
  6. dependencies {
  7. classpath 'com.android.tools.build:gradle:1.3.1'
  8. classpath 'de.undercouch:gradle-download-task:3.4.3'
  9. // NOTE: Do not place your application dependencies here; they belong
  10. // in the individual module build.gradle files
  11. }
  12. }

发现终于不报这个错了

2.google()方法找不到

  1. * Where:
  2. Build file '/****/react-native-0.57.7/build.gradle' line: 9
  3. * What went wrong:
  4. A problem occurred evaluating root project 'react-native-0.57.7'.
  5. > Could not find method google() for arguments [] on repository container.

那就按照提示的位置注释掉这个文件中所有google()方法,重新编译

3.子项目无法引入

  1. * Where:
  2. Build file '/****/react-native-0.57.7/ReactAndroid/build.gradle' line: 7
  3. * What went wrong:
  4. Error resolving plugin [id: 'com.android.library']
  5. > Plugin 'com.android.library' is already on the script classpath.
  6. Plugins on the script classpath cannot be applied in the plugins {} block.
  7. Add "apply plugin: 'com.android.library'" to the body of the script to use the plugin.

具体指明的是这里的代码

  1. plugins {
  2. id("com.android.library")
  3. id("maven")
  4. id("de.undercouch.download")
  5. }

那就统统改下

  1. apply plugin: 'com.android.library'
  2. apply plugin: 'maven'
  3. apply plugin: 'de.undercouch.download'

4.不推荐使用NDK?

  1. * Where:
  2. Build file '/Users/zhangdong/Downloads/react-native-0.57.7/ReactAndroid/build.gradle' line: 263
  3. * What went wrong:
  4. A problem occurred evaluating project ':ReactAndroid'.
  5. > Error: NDK integration is deprecated in the current plugin.
  6. Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
  7. Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.

按照提示在ReactAndroid中的gradle.properties文件中加入android.useDeprecatedNdk=true

5.gradle3.0一下不支持api方式引入第三方库

  1. * Where:
  2. Build file '/****/react-native-0.57.7/ReactAndroid/build.gradle' line: 300
  3. * What went wrong:
  4. A problem occurred evaluating project ':ReactAndroid'.
  5. > 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.找不到依赖

  1. * What went wrong:
  2. A problem occurred configuring project ':ReactAndroid'.
  3. > Failed to notify project evaluation listener.
  4. > Could not resolve all dependencies for configuration ':ReactAndroid:_debugCompile'.
  5. > Could not find com.android.support:appcompat-v7:27.1.1.
  6. Searched in the following locations:

最外层build.gradle的allprojects中添加

  1. maven {
  2. url "https://maven.google.com"
  3. }

7.ReactAndroid/build.gradle文件报错

  1. * What went wrong:
  2. Execution failed for task ':ReactAndroid:buildReactNdkLib'.
  3. > Process 'command '/Users/zhangdong/Library/Android/android-ndk-r10e/ndk-build'' finished with non-zero exit value 2

What??又是这个错,完全没有指明什么错误,查看ReactAndroid/build.gradle文件发现有些标红找不到,先注释掉,这只是一些异常捕获和编译环境的判断没有什么大碍

8.第三方库找不到对应文件

  1. make: *** No rule to make target `/****/react-native-0.57.7/ReactAndroid/build/third-party-ndk/glog/glog-0.3.5/src/demangle.cc',
  2. needed by `/****/react-native-0.57.7/ReactAndroid/build/tmp/buildReactNdkLib/local/armeabi-v7a/objs/glog/glog-0.3.5/src/demangle.o'. Stop.
  3. 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同样如此

 

未完待续

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/737736
推荐阅读
相关标签
  

闽ICP备14008679号