我在项目中添加了一个npm库,此后,Android版本不再起作用。 iOS版本工作正常。我添加的库是https://www.npmjs.com/package/react-native-connectivity-status
当我尝试运行react-native run-android时,我收到错误消息“> Android依赖项'com.google.android.gms:play-services-basement'对于编译(11.8.0)和运行时具有不同的版本(15.0.1)类路径。您应该通过DependencyResolution手动设置相同的版本。
在应用程序build.gradle中,我添加了:
implementation project(':react-native-connectivity-status') // to check if BT is turned on
此post表示我要做的就是添加
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。我已经做了。我还将所有的compile语句都转换为实现。
所以现在我的根目录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-basement。
发布此问题之前,我已经查看了许多答案:here,here和here
我意识到我没有在默认Config中添加multiDexEnabled true。添加它之后,运行./gradlew clean,然后运行本机运行Android,我收到一个新错误:>设置了Android依赖项'com.google.android.gms:play-services-tasks-license:11.8.0'只能编译/不支持
答案 0 :(得分:0)
我能够通过添加来构建它(带有新的和改进的错误):
implementation("com.google.android.gms:play-services-basement:15.0.1")
implementation("com.google.android.gms:play-services-base:15.0.1")
在应用程序级别到build.gradle中的依赖项。