我在添加以下行后尝试构建我的gradle
implementation "com.android.support:appcompat-v7:${versions.supportLib}"
implementation "com.android.support:recyclerview-v7:${versions.supportLib}"
implementation "com.android.support:support-annotations:${versions.supportLib}"
implementation "com.android.support:design:${versions.supportLib}"
我收到以下错误
Error:(32, 0) Could not get unknown property 'versions' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
<a href="openFile:C:\Users\Sagar\Desktop\SickLab\app\build.gradle">Open File</a>
我的整个成绩档案如下
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.sagar.sicklab"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation("com.mikepenz:materialdrawer:6.0.1@aar") {
transitive = true
}
implementation "com.android.support:appcompat-v7:${versions.supportLib}"
implementation "com.android.support:recyclerview-v7:${versions.supportLib}"
implementation "com.android.support:support-annotations:${versions.supportLib}"
implementation "com.android.support:design:${versions.supportLib}"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:support-v4:26.+'
compile 'com.android.support:design:26.+'
compile 'com.google.android.gms:play-services-ads:11.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.github.apl-devs:appintro:v4.2.2'
compile 'eu.long1:spacetablayout:1.0.4'
}
答案 0 :(得分:0)
问题是你还没有定义一个有针对性的命名&#34;版本&#34;那个gradle可以访问。错误消息表明它无法找到它。
无法获取未知属性&#39;版本&#39;对于org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler类型的对象
您需要定义一个名为版本的对象,该对象具有一个名为&#34; supportLib&#34;的变量。并保存您要使用的支持库的值。
我之前从未这样做过,所以可能完全错了,但是这里有一些伪代码可以帮助你定义你的对象:
version = new Version(supportLib: "26.1.0")
class Version {
String supportLib
String toString() {
supportLib
}
}
您可以在同一个build.gradle文件中定义它。执行gradle时会发生什么,它将实例化versions对象并从supportLib字段读取版本字符串值并将其附加到支持库String。话虽如此,我从未见过&#34;实现&#34; com.android.support:recyclerview-v7:$ {versions.supportLib}&#34;之前的语法,所以你肯定需要实验。 Here是给我伪代码的网站。
答案 1 :(得分:0)
只需添加您的文件:
ext {
supportLibraryVersion = "25.3.1"
}
并替换:
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:support-v4:$supportLibraryVersion"
compile "com.android.support:cardview-v7:$supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
compile "com.android.support:design:$supportLibraryVersion"