多个具有包名称的库会对原生进行反应

时间:2018-03-21 11:26:31

标签: android react-native

任务执行失败':react-native-device-info:processReleaseResources'。

  

错误:包含名称为“com.google.android.gms.license”的多个库

2 个答案:

答案 0 :(得分:2)

在android / build.gradle中添加

...
allprojects {
    repositories {
        ...
        configurations.all {
            resolutionStrategy {
                ...
                force 'com.google.android.gms:play-services-gcm:11.6.0'
            }
        }
    }
}

或者您可以直接更改模块(不推荐)

... / node_modules /反应天然器件用方式/机器人/的build.gradle

compile 'com.google.android.gms:play-services-gcm:11.6.0'

答案 1 :(得分:0)

我的方法是扫描所有Android项目并将google play服务的版本直接更新到每个模块build.gradle。

步骤1:在项目中创建名为android-gradle-fix.js的js文件

tableView.selectRow(at: nil, animated: true, scrollPosition: .none)

步骤2:更新 package.json 文件

中的npm脚本
#!/usr/bin/env node

const fs = require('fs')

try {
  console.log('Fix Start')
  var rootDir = process.cwd()
  // @nhancv: Preparing path
  var androidSettingGradleFile = `${rootDir}/android/settings.gradle`
  var androidSettingGradleFileData = fs.readFileSync(androidSettingGradleFile, 'utf8')
  var pathArr = []
  var keySearch = ".projectDir = new File(rootProject.projectDir, '../"
  var keyIndex = 0
  while ((keyIndex = androidSettingGradleFileData.indexOf(keySearch, keyIndex)) !== -1) {
    var nextIndex = keyIndex + keySearch.length
    var path = androidSettingGradleFileData.substring(nextIndex, androidSettingGradleFileData.indexOf("')", nextIndex))
    pathArr.push(path)
    keyIndex++
  }

  var newVersion = '11.8.0'
  var key = 'com.google.android.gms'
  // @nhancv: Update version
  for (var i = 0; i < pathArr.length; i++) {
    var file = `${rootDir}/${pathArr[i]}/build.gradle`
    var data = fs.readFileSync(file, 'utf8')
    var result = data
    var index = 0
    var logs = []
    while ((index = data.indexOf(key, index)) !== -1) {
      var versionIndexOf = data.indexOf(':', index + key.length + 1) + 1
      var endVersionIndexOf = data.indexOf(data[index-1], versionIndexOf + 1)
      var moduleOrigin = data.substring(index, endVersionIndexOf)
      var moduleNew = data.substring(index, versionIndexOf) + newVersion
      if (moduleOrigin !== moduleNew) {
        logs.push(`Replace: ${moduleOrigin} -> ${moduleNew}`)
        result = result.replace(moduleOrigin, moduleNew)
        fs.writeFileSync(file, result, 'utf8')
      }
      index++
    }
    if (logs.length > 0) {
      console.log(`Fix path: ${pathArr[i]}`)
      for (var j = 0; j < logs.length; j++) {
        console.log(`=> ${logs[j]}`)
      }
    }
  }
  console.log('Fix Done')
} catch (error) {
  console.error(error)
}

当你运行npm install时,它将扫描所有android模块并使用特定版本11.8.0进行更新(你可以在android-gradle-fix.js文件中更改它)

运行npm install时,它将跳过安装后的过程,您可能会遇到错误:

postinstall:无法在wd%s%s(wd =%s)节点中运行

==&GT;将add - unsafe-perm修复为npm install,如

"scripts": {
    "postinstall": "node ./android-gradle-fix.js"
  },

详细信息:https://medium.com/p/2fd245027832

希望它可以帮到你。