When using compile 'com.google.android.support

2019-02-19 18:26发布

When using compile 'com.google.android.support:wearable:2.0.4' (the latest version of com.google.android.support:wearable) in my Wear app's build.gradle file, I get the error below, but I am not using 26.0.0.

What should I do? Even if I add compile 'com.android.support:wear:26.0.0' it still fails.

Error in the project's gradle file: 

Error:(22, 13) Failed to resolve: com.android.support:wear:26.0.0
<a href="install.m2.repo">Install Repository and sync project</a><br><a href="openFile:/.../wear/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>

1条回答
家丑人穷心不美
2楼-- · 2019-02-19 19:17

Many of the Wear elements (BoxInsetLayout, WearableRecyclerView, SwipeDismissFrameLayout, full list here) have been moved to the main android support library (details). You can continue to use the old classes, but you probably want to use the latest stuff.

The build.gradle for your wear app includes compile 'com.google.android.support:wearable:2.0.4' which uses some classes from com.android.support:wear:26.0.0. As called out in link above, they were moved from com.google.android.support:wearable to com.android.support:wear.

The support libraries (26) are now in Google's Maven repository (not downloaded via the support repository from the SDK Manager), so you need to add Google's Maven Repository your top level build.gradle file.

In allprojects, within repositories, add the code below. It goes under the jcenter() call.

For the Android Gradle plugin revision 2.3.3 with Gradle 3.3 (Android Studio 2.3.3), your code should look like this:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

For the Android Gradle plugin revision 3.0.0 (in alpha right now) with Gradle 4.1 (might be milestone version) in Android Studio 3.0.0, your code should look like this:

allprojects {
    repositories {
        jcenter()
        google()
    }
}
查看更多
登录 后发表回答