问题
Everything has been working and compiling fine until I've added a TabLayout to an .xml layout. After I added it, the project just refused to compile and either all of my .xml files stopped showing anything and all of my library imports say "cannot resolve symbol ...".
I don't understand why all of my imports which had previously been compiling well now simply say:
Failed to resolve: com.android.support:support-v13:26
Failed to resolve: com.android.support:appcompat-v7:26
and none of buttons provided (e.g. "Install repository and sync project") are clickable.
Please, have a look at the gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.prett.myapplication"
minSdkVersion 22
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'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26'
compile 'com.android.support:support-v13:26'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
}
I've tried "Invalidate caches/restart", but it didn't have any impact.
P.S.
compile 'com.android.support:design:25.3.1'
says that
This support library should not use a different version (25) than the compileSdkVersion (26)
Could this also be causing the issue?
回答1:
If your compile SDK version is 26, android support dependencies version should be 26.x.x
Set your gradle dependencies as follow:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:26.0.1'
}
If you still get compile errors, add google maven repository to Project Gradle
file:
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
回答2:
Try below dependency in gradle and rebuild project;
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support:design:26.0.1'
回答3:
This support library should not use a different version (25) than the compileSdkVersion (26)
means you have to update your support library from version 25 to 26 and problem will get resolved.
来源:https://stackoverflow.com/questions/46360868/failed-to-resolve-com-android-supportsupport-v1326