Failed to build Android Hello World application in

2019-07-19 23:38发布

问题:

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 claims to 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.

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

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?

回答1:

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.

From the Android Studio 0.4.0 release notes:

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 Plugin page includes instructions for manually getting the Gradle build tools.



回答2:

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

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).



回答3:

Go to Preferences > Gradle > Offline work

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