Java 无法在离线模式下构建 Android Hello World 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20746071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:03:08  来源:igfitidea点击:

Failed to build Android Hello World application in offline mode

javaandroidbuildgradle

提问by PermanentGuest

I'm new to Android development. I work on a system that doesn't have an internet connection. I have installed the new Android Developer studio which claimsto be supporting offline development. I have updated the Gradle to 1.9 (by copying the downloaded zip file to the folder "C:\Documents and Settings\.gradle\wrapper\dists\gradle-1.9-all\3jdgemv0iv8uqohg3kcp2o88r1". It is clear that the developer studio did detect this and unpacked the gradle in that folder.

我是 Android 开发的新手。我在没有互联网连接的系统上工作。我已经安装了声称支持离线开发的新 Android Developer Studio 。我已将 Gradle 更新为 1.9(通过将下载的 zip 文件复制到文件夹“C:\Documents and Settings\.gradle\wrapper\dists\gradle-1.9-all\3jdgemv0iv8uqohg3kcp2o88r1”。很明显,开发人员工作室确实检测到这并解压缩该文件夹中的gradle。

After this I created a new HelloWorld project and tried to build it, I get the following error.

在此之后,我创建了一个新的 HelloWorld 项目并尝试构建它,但出现以下错误。

Gradle: A problem occurred configuring project ':app'.

> Could not resolve all dependencies for configuration ':app:classpath'.

   > Could not resolve com.android.tools.build:gradle:0.7.+.
     Required by:
        HellowWorld1:app:unspecified

      > No cached version of com.android.tools.build:gradle:0.7.+ available for offline mode.

Do you know what is causing this? How do I solve this? Is there any other file which I should update with the information w.r.t the manually installed Gradle version?

你知道是什么原因造成的吗?我该如何解决这个问题?是否有任何其他文件我应该使用手动安装的 Gradle 版本的信息更新?

回答by Bryan Herbst

Though you can now build Gradle projects without an active internet connection, you still need to download the dependencies once before offline mode will work. If you don't build once with offline mode disabled, you won't have any of the dependencies on your system and the build will fail.

虽然您现在可以在没有活动的互联网连接的情况下构建 Gradle 项目,但您仍然需要在离线模式工作之前下载依赖项。如果您没有在禁用离线模式的情况下构建一次,您的系统将没有任何依赖项,构建将失败。

From the Android Studio 0.4.0 release notes:

来自 Android Studio 0.4.0 发行说明:

Note that if you add a new dependency you'll still need to have a network connection to download the artifact. If you somehow forget that you are in offline mode, there is a balloon tip for that.

请注意,如果您添加新的依赖项,您仍然需要有网络连接才能下载工件。如果您以某种方式忘记了您处于离线模式,则有一个气球提示。

The Building the Android Gradle Pluginpage includes instructions for manually getting the Gradle build tools.

大厦的Android摇篮插件页面包括手动获取摇篮构建工具的说明。

回答by ahmed

Had the same error after updating Android Studio today. For me, it wasn't a matter of proxy settings:

今天更新 Android Studio 后出现同样的错误。对我来说,这不是代理设置的问题:

Uncheck "Offline work" in File>Settings>Gradle>Global Gradle Settings and resync the project, for example by restarting your Android Studio IDE. Once synced, you can check the option again to work offline (Gradle version 0.11... and Android Studio version 0.6.0 Preview).

在 File>Settings>Gradle>Global Gradle Settings 中取消选中“Offline work”并重新同步项目,例如通过重新启动 Android Studio IDE。同步后,您可以再次选中该选项以离线工作(Gradle 版本 0.11... 和 Android Studio 版本 0.6.0 预览版)。

回答by Sonic Master

Go to Preferences > Gradle > Offline work

转到首选项 > Gradle > 离线工作

Make sure you unchecked Offline Work. I had same problem, and that works fine.

确保您取消选中离线工作。我有同样的问题,而且效果很好。