如何运行"Watchface for wearos"代码实验室? [英] How to run "Watchface for wearos" codelab?

查看:140
本文介绍了如何运行"Watchface for wearos"代码实验室?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android和WearOS以及Gradle的新手,我只想遵循此Codelab:

I am new to Android and WearOS and also to Gradle, and I just want to follow along this Codelab:

https://codelabs.developers.google.com/codelabs/watchface/index.html#0

所以我下载了Android Studio并导入了项目

So I downloaded Android Studio and imported the project

https://github.com/googlecodelabs/watchface

但是在编译时我得到了错误

but when compiling I just get the error

无法解决:com.google.android.support:wearable:2.0.0

Failed to resolve: com.google.android.support:wearable:2.0.0

我已经尝试更改SDK版本和其他内容,但没有帮助.我很确定这只是几个版本设置,但我不知道在哪里看.

I already tried to change SDK Versions and other things, but it didn't help. I'm pretty sure it's just a few version settings, but I have no idea where to look.

有人可能会完成此代码实验室,并使其与AndroidStudio的实际"版本一起运行吗?

Did anyone maybe complete this codelab and made it run with the "actual" version of AndroidStudio?

谢谢,托尔斯滕

推荐答案

github上的代码最后一次更新是在2017年5月,这真是遗憾,因为它是对表面的有用介绍.从那时起,许多事情发生了变化.从2018年11月开始,github上甚至有一个gradle更新的拉取请求,但尚未合并.

The code on github was last updated in May 2017, which is a shame, as it is a useful introduction to watchfaces. A number of things have changed since then. There is even a pull request on github with gradle updates from Nov 2018, but it hasn't been merged.

您的无法解决"错误很可能与Google现在(除了jcenter之外)在其自己的Maven存储库中提供了一些软件包有关.

Your 'Failed to resolve' error is likely related to Google now providing some packages in their own Maven repository, in addition to jcenter.

可以通过将google()添加到Package build.gradle文件中的存储库闭包中来解决此问题:

This can be fixed by adding google() to the repositories closures in the Package build.gradle file:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.2'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

gradle插件的版本也已更改为上述4.0.2,因此还要使用以下命令更新gradle-wrapper.properties文件:

The version of the gradle plugin has been changed to 4.0.2 above too, so also update the file gradle-wrapper.properties with:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

Gradle现在应该可以构建,但是它可能仍会在构建"窗口中记录一些警告或错误,您可以在Android Studio的底部打开该窗口.

Gradle should now build, but it may still log some warnings or errors in the Build window which you can open at the bottom of Android Studio.

gradle依赖关键字"provided"已被"compileOnly"替换,"compile"已被"implementation"替换.Android Studio中的Shift + Ctrl + R键可让您轻松地在整个项目范围内进行替换.

The gradle dependency keyword 'provided' has been replaced with 'compileOnly' and 'compile' with 'implementation'. Shift+Ctrl+R in Android Studio will enable you to easily do the replacement project-wide.

对于在所有模块build.gradle文件中将compileSdkVersion和targetSdkVersion(更新为30)和buildToolsVersion(更新为30.0.2)也应该是有用的.

It should also be useful for updating compileSdkVersion and targetSdkVersion (to 30) and buildToolsVersion (to 30.0.2) in all the module build.gradle files.

该软件包的版本已过时,可穿戴设备的当前版本为2.8.1,而play-services-wearable的版本为17.0.0.Ctrl + Alt + Shift + S会带您进入项目结构"中的建议",这可以在将来帮助您保持最新状态.

The package versions are out of date, with the wearable ones currently at 2.8.1 and play-services-wearable at 17.0.0. Ctrl+Alt+Shift+S takes you to 'Suggestions' in 'Project Structure', which can help you in future to stay current.

最后一个问题是,为了支持jetpack/androidx,Android支持库已经过时了.请参见旧参考书.

The last problem is that the Android Support Library has been obsoleted in favor of jetpack/androidx. See the old reference.

在此项目中,这仅是模块5-palette的build.gradle中的问题.您可以将'com.android.support:palette-v7:23.3.0'替换为'androidx.palette:palette:1.0.0'.请参阅 Jetpack神器映射.然后,您需要在MyWatchFaceService.java中更改import语句.

In this project, it is only a problem in the build.gradle of module 5-palette. You may replace 'com.android.support:palette-v7:23.3.0' with 'androidx.palette:palette:1.0.0'. See Jetpack Artifact Mappings. You then need to change the import statement in MyWatchFaceService.java.

最后将以下行添加到gradle.properties:

Finally add the following line to gradle.properties:

android.useAndroidX=true

这篇关于如何运行"Watchface for wearos"代码实验室?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆