导入 Snackbar 时出错
Error while importing Snackbar
我正在尝试使用以下命令导入 Snackbar。但是出现错误 Cannot Resolve symbol Snackbar
。这里可能的问题是什么?我尝试添加 "android.support.design" 依赖项但没有成功。
import android.support.design.widget.Snackbar
我的build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "in.anamika.anamika"
minSdkVersion 15
targetSdkVersion 27
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'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.9.7'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
您的 build.gralde
中缺少设计库的依赖项。更新如下:
dependencies {
...
implementation 'com.android.support:design:27.1.1'
...
}
更新文件后,点击右上角的Sync Now
。确保您有互联网连接,以便可以下载依赖项。
如果在那之后您仍然遇到问题,请清理并重建您的项目。
Snackbar
属于Maven神器com.android.support:design:27.1.1
您需要添加设计库的依赖
在您的 build.gradle
中添加以下依赖项
implementation 'com.android.support:design:27.1.1'
比Clean - Re-Build - Run
你的项目
If you are migrating to androidx then use
com.google.android.material.R.id.snackbar_text
而不是
android.support.design.R.id.snackbar_text
不要错过导入 import com.google.android.material.snackbar.Snackbar;
同时实施implementation "com.google.android.material:material:1.2.0-alpha02"
设计您需要在 build.gradle
文件中添加 dependencies
。
implementation 'com.android.support:design:27.1.1'
还有Sync
你的项目。
我尝试导入 Snackbar
库时出错
implementation 'com.android.support:design:27.1.1'
并且我收到了新的错误,说支持库的版本应该与 compileSDKVersion 版本相同,所以我将实现更改为
implementation 'com.android.support:design:28.0.0'
它修复了错误,我可以使用 Snackbar
。
我正在尝试使用以下命令导入 Snackbar。但是出现错误 Cannot Resolve symbol Snackbar
。这里可能的问题是什么?我尝试添加 "android.support.design" 依赖项但没有成功。
import android.support.design.widget.Snackbar
我的build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "in.anamika.anamika"
minSdkVersion 15
targetSdkVersion 27
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'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.9.7'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
您的 build.gralde
中缺少设计库的依赖项。更新如下:
dependencies {
...
implementation 'com.android.support:design:27.1.1'
...
}
更新文件后,点击右上角的Sync Now
。确保您有互联网连接,以便可以下载依赖项。
如果在那之后您仍然遇到问题,请清理并重建您的项目。
Snackbar
属于Maven神器com.android.support:design:27.1.1
您需要添加设计库的依赖
在您的 build.gradle
中添加以下依赖项implementation 'com.android.support:design:27.1.1'
比Clean - Re-Build - Run
你的项目
If you are migrating to androidx then use
com.google.android.material.R.id.snackbar_text
而不是
android.support.design.R.id.snackbar_text
不要错过导入 import com.google.android.material.snackbar.Snackbar;
同时实施implementation "com.google.android.material:material:1.2.0-alpha02"
设计您需要在 build.gradle
文件中添加 dependencies
。
implementation 'com.android.support:design:27.1.1'
还有Sync
你的项目。
我尝试导入 Snackbar
库时出错
implementation 'com.android.support:design:27.1.1'
并且我收到了新的错误,说支持库的版本应该与 compileSDKVersion 版本相同,所以我将实现更改为
implementation 'com.android.support:design:28.0.0'
它修复了错误,我可以使用 Snackbar
。