英文:
android.support.design.widget.TabLayout - cannot resolve symbol 'design'
问题
我尝试导入 android.support.design.widget.TabLayout,但出现了无法解析符号 'design' 的错误。
在一开始,我以为问题是 implementation com.android.support:design 版本(在 gradle Module 中)的问题。但事实并非如此。我成功找到了这个错误的原因 - 依赖版本(在 gradle Project 中)。
我的依赖版本是:
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.google.gms:google-services:4.3.3'
因此,如果我使用旧版本 - 这将修复错误。
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:3.2.1'
我不明白为什么它不能与最新版本一起使用。请帮助我理解这个问题,为什么我不能使用新版本。
我的 Android Studio 版本是: 4.0
gradle Module:
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "mv.group.qwerty"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
gradle Project:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.google.gms:google-services:4.3.3'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
英文:
I tried to import android.support.design.widget.TabLayout, but I got cannot resolve symbol 'design' error.
In the First I sought that is a problem with a implementation com.android.support:design version (in gradle Module).
But it is not.
I managed to find the cause of this error - dependencies versions (in gradle Project).
My dependencies version is:
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.google.gms:google-services:4.3.3
'
So if I use older version - this is fixing the error.
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:3.2.1'
I do not understand why It does not work with newest versions.
Please help me understand this, why I cannot use new versions.
My android studio vesrion is: 4.0
gradle Module:
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "mv.group.qwerty"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
gradle Project:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.google.gms:google-services:4.3.3'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案1
得分: 1
Solution 1:
将以下代码添加到你的 build.gradle(Module:App)
的依赖中,
implementation 'com.android.support:design:28.0.0-alpha3'.
同时确保所有的 Android Support 依赖版本相同,就像下面这样:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation "com.android.support:cardview-v7:28.0.0-alpha3"
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
implementation 'com.android.support:design:28.0.0-alpha3'
}
Solution 2:
你是否将依赖项转换为了 androidx
?
在菜单中,点击 Refector
,然后选择 Migrate to AndroidX
,点击 sync gradle
,这应该可以解决这个问题。
并且使用 implementation 'com.google.android.material:material:1.0.0'
替代 implementation 'com.android.support:design:28.0.0-alpha3'
。
英文:
Solution 1:
add this to your build.gradle(Module:App)
dependencies,
implementation 'com.android.support:design:28.0.0-alpha3'.
Also Make sure that all Android Support dependencies have the same version like below:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation "com.android.support:cardview-v7:28.0.0-alpha3"
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
implementation 'com.android.support:design:28.0.0-alpha3'
}
Solution 2:
Did you convert your dependencies to androidx
?
In Menu, press Refector
and select Migrate to AndroidX
, press sync gradle
and it should solve this issue.
and use implementation 'com.google.android.material:material:1.0.0'
instead of implementation 'com.android.support:design:28.0.0-alpha3'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论