我遇到以下错误
无法获得类型对象的未知属性'supportLibVersion' org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHand
我正在开发react-native应用程序,并且react-native-maps依赖项在下面出现错误
dependencies {
def supportLibMajorVersion = supportLibVersion.split('\\.')[0] as int
def appCompatLibName = (supportLibMajorVersion < 20) ? "androidx.appcompat:appcompat" : "com.android.support:appcompat-v7"
implementation "$appCompatLibName:$supportLibVersion"
implementation('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}
implementation "com.google.android.gms:play-services-base:${safeExtGet('playServicesVersion', '16.1.0')}"
implementation "com.google.android.gms:play-services-maps:${safeExtGet('playServicesVersion', '16.1.0')}"
implementation 'com.google.maps.android:android-maps-utils:0.5'
}
任何人都可以知道这里出了什么问题吗?
终端错误是
失败:生成失败,发生异常。
位置:
构建文件'D:\ react native \ abhishek \ Gwala \ node_modules \ react-native-maps \ lib \ android \ build.gradle'行:20出了什么问题:
评估项目':react-native-maps'时发生问题。
无法获得类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的对象的未知属性'supportLibVersion'。
第20行是
def supportLibMajorVersion = supportLibVersion.split('\\.')[0] as int
答案 0 :(得分:16)
在supportLibVersion = "28.0.0"
内添加android/build.gradle
-> ext
示例:
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
答案 1 :(得分:5)
在supportLibVersion = "28.0.0"
中的buildscript
中添加android/build.gradle
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0" // <=== add this line
}
...
}
https://github.com/react-native-community/react-native-maps/issues/3108#issuecomment-552795543
答案 2 :(得分:3)
尝试直接从github安装它:
npm install --save git+https://git@github.com/react-native-community/react-native-maps.git
答案 3 :(得分:2)
这些步骤之后,我解决了这个问题:
将此行添加到\node_modules\react-native-maps\lib\android\build.gradle -- line: 20
def supportLibVersion = safeExtGet('supportLibVersion', '28.0.0')
在AndroidManifest.xml
下的<application>
中:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
答案 4 :(得分:0)
在android目录中的文件build.gradle中
(... / YourApp / android / build.gradle)
找到ext部分并添加
supportLibVersion =“ 28.0.0” ext { ... supportLibVersion =“ 28.0.0”}
应该完成的工作。
答案 5 :(得分:0)
在node_modules/react-native-maps/lib/android/build.gradle
中添加以下行:
在dependencies
下
def supportLibVersion = safeExtGet('supportLibVersion', '28.0.0')
示例:
https://github.com/react-native-community/react-native-maps/blob/master/lib/android/build.gradle
希望有帮助。