问题
I want to use Google architecture components in my app, but after updating android studio to version 3.1.1 when I add android.arch.lifecycle:extensions:1.1.1
dependency into app.gradle file, it will show Failed to resolve: support-fragment
My gradle version is 4.4
This is app gardle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "ir.apptori.myapplication"
minSdkVersion 17
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'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
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'
implementation "android.arch.lifecycle:extensions:1.1.1"
}
Please guid me how to fix it, Thanks
回答1:
I had a similar error and changing the repositories
order so that google()
comes before jcenter()
fixed it.
I had to change the order for the repositories
within buildscript
and allprojects
in the top level build.gradle
file.
Please see this commit: https://github.com/kunadawa/ud851-Exercises/commit/9f6720ef4d52c71b206ddaa8477f2cf6e77a66f4
回答2:
I also had to remove the maven url from the project build.gradle as in:
buildscript {
repositories {
google()
jcenter()
// maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
This now works for me.
回答3:
i add this line in build.gradle and fixed bug :
implementation 'androidx.fragment:fragment:1.2.5'
回答4:
This just happened to me with a project I cloned from github.
I updated my SDK and buildtools and had to double check all the dependencies to match the buildToolsVersion
and the compileSdkVersion
from the project.
The error message wasn't very clear when I tried to sync the project, it only gave me a more explicit error when I tried to run and it failed.
Could not find support-fragment.jar (com.android.support:support-fragment:27.0.2).
Good Luck!
回答5:
for a similar issue its solved by changing material implementation from alpha2 version to alpha 7 in the app build.gradle file
implementation 'com.google.android.material:material:1.1.0-alpha07'
回答6:
add these two to build.gradle -> repositories
{
mavenCentral()
google()
}
and add to these are to allprojects
allprojects {
repositories {
mavenCentral()
google()
}
}
来源:https://stackoverflow.com/questions/49781097/failed-to-resolve-support-fragment-error-when-add-google-architecture-component