我在项目中添加了一个npm库,从那时起,android版本就不再工作了。iOS版本运行良好。我添加的库是https://www.npmjs.com/package/react-native-connectivity-status
当我尝试运行react native run android时,我会收到错误消息">android dependency‘com.google.android.gms:play services baser’的编译(11.8.0)和运行时(15.0.1)类路径有不同的版本。您应该通过DependencyResolution手动设置相同的版本"。
在应用程序build.gradle中,我添加了:
implementation project(':react-native-connectivity-status') // to check if BT is turned on
这篇帖子表明我所需要做的就是添加
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.0.2"
}
}
}
}
到根级别build.gradle。我已经做到了。我还将所有的编译语句切换到了实现。
所以现在我的根级别build.gradle现在看起来像:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
// Add jitpack repository (added by react-native-spinkit)
maven { url "https://jitpack.io" }
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.0.2"
}
}
}
}
}
以下是我的build.gradle 中的依赖项列表
dependencies {
implementation project(':react-native-i18n')
implementation project(':react-native-svg')
implementation project(':react-native-extra-dimensions-android')
implementation project(':react-native-google-analytics-bridge')
implementation project(':react-native-splash-screen')
implementation project(':react-native-image-picker')
implementation project(':react-native-spinkit')
implementation project(':react-native-fbsdk')
implementation project(':react-native-picker')
implementation 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.facebook.react:react-native:+'
// From node_modules
implementation 'com.facebook.fresco:fresco:1.3.0'
implementation 'com.facebook.fresco:animated-gif:1.3.0'
implementation project(':blelibrary')
implementation project(':gaialibrary')
implementation project(':vmupgradelibrary')
implementation 'com.google.code.gson:gson:2.8.4'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation project(':react-native-connectivity-status') // to check if BT is turned on
}
以及一些附加信息
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.someapp"
minSdkVersion 19
targetSdkVersion 26
versionCode 28
versionName "1.2.4"
ndk {
abiFilters "armeabi-v7a", "x86"
}
packagingOptions {
exclude "lib/arm64-v8a/libgnustl_shared.so"
}
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_static'
}
}
}
我对这个错误消息感到非常困惑,因为我在build.gradle.的任何地方都看不到com.google.android.gms:play services department
在发布这个问题之前,我已经看了很多答案:这里,这里和这里
我意识到我没有在默认配置中添加multiDexEnabled true。添加后,运行/gradlew清理然后反应原生运行android,我得到一个新的错误:>android依赖项"com.google.android.gms:play services tasks license:11.8.0"设置为compileOnly/provided,这不支持
我能够通过在应用程序级别的build.gradle中添加以下依赖项来构建它(有新的和改进的错误):
implementation("com.google.android.gms:play-services-basement:15.0.1")
implementation("com.google.android.gms:play-services-base:15.0.1")