Android Studio : Unknown host - android

Facing the following issue with Android Studio after an update today.
Error
Unknown host 'This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server'. You may need to adjust the proxy settings in Gradle.
Enable Gradle 'offline mode' and sync project
Learn about configuring HTTP proxies in Gradle
When I click on "Enable offline mode", get the following error:
Error:No cached version of com.android.tools.build:gradle:2.14.1 available for offline mode.
Disable Gradle 'offline mode' and sync project
What I have tried:
Options are based on other posts/ suggestions:
a. File > Settings > Build, Execution, Developement > Gradle
Selected the right folder for Gradle.
b. Updated build.gradle file (Project file and NOT Module)
//classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.14.1'
Despite these changes .. the error persists.
Any help or suggestions .. thanks in advance !

When I update to 1.5.1 the classpath was
classpath com.android.tools.build:gradle:1.2.3
It give me error like yours.
I tried to change it to
classpath com.android.tools.build:gradle:1.5.1
It didn't work but when I change it to
classpath com.android.tools.build:gradle:1.5.0
It worked.
So you should give it a shot play with the numbers it might work.

File > Settings > Build, Execution, Developement > Gradle>Experimental> Check: "Allow Module selection on project import"
2.Sync Gradle again

Related

Sync project in android studio failed

I'm totally new in android programming and by now just trying to run a "Hello World" program! But I couldn't! This is what I've done till now:
Previously I had android-studio-ide-171.4443003-windows installed on my laptop, and I installed all SDK Tools from SDK manager. But every time I wanted to sync a project it end up with this error:
ERROR: Could not find com.android.tools.build:gradle:3.5.0. Searched
in the following locations:
- file:/C:/Users/Pro/.android/manual-offline-m2/android-gradle-plugin-3.5.0-beta01/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
- file:/C:/Users/Pro/.android/manual-offline-m2/android-gradle-plugin-3.5.0-beta01/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
- file:/C:/Users/Pro/.android/manual-offline-m2/gmaven_stable/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
- file:/C:/Users/Pro/.android/manual-offline-m2/gmaven_stable/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
Required by:
project : Open File
then I updated my android studio to android-studio-ide-191.5791312-windows32, and again it get that error! so I download android-gradle-plugin-3.5.0-beta01 and gmaven_stable from android developer site and as the site said, I extracted them and copy the content into [my home directory]\.android\manual-offline-m2. and then restart android studio, but the problem still exist!
Then I went to Settings > Build, Execution, Deployment > Gradle and checked the "Offline work" and specified the "Service directory path" as "[my home directory]/.android/manual-offline-m2/android-gradle-plugin-3.5.0-beta01" and again tried to sync the project, but sync got new error:
ERROR: No cached version of com.android.tools.build:gradle:3.5.0 available
for offline mode.
now I'm totally confused and don't know what should I do to solve this problem! If anybody help me I will really appreciate that.
Open android studio go to your project -> build.gradle -> edit this code
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
Try lowering your build.gradle version to classpath 'com.android.tools.build:gradle:3.4.2'
I think your android studio does not support that kind of classpath version.

Android Studio offline add `Android plugin for Gradle`

I use Android Studio 3.1.2 with Gradle 4.4 and have to force Gradle to do off-line work, because when I use it normally (on-line), it takes to long to sync and fails. At first I got this error:
No cached version of com.android.tools.build:gradle:3.1.2 available for offline mode.
Disable Gradle 'offline mode' and sync project
So I downloaded gradle-3.1.2.jar, put it in <project root>/libs/ and change build.gradle of my project to this state:
buildscript {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
Now it seems that previous error is solved but another one is raised:
Unable to load class 'com.android.tools.lint.gradle.api.ToolingRegistryProvider'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
How I can solve this problem?
Edit
I know the normal way is working on-line, at least for the first build. But there must be a way to add it off-line. Isn't there such way?
This is from android studio manual from this link.
Turn on Offline Mode for Gradle: If you have limited bandwitch, turn
on Offline Mode to prevent Gradle from attempting to download missing
dependencies during your build. When Offline Mode is on, Gradle will
issue a build failure if you are missing any dependencies, instead of
attempting to download them. To turn on Offline Mode, proceed as
follows:
Click File > Settings (on a Mac, Android Studio > Preferences) to
open the Settings dialog.
In the left pane, expand Build, Execution, Deployment and then click
Gradle.
Under Global Gradle settings, check the Offline work checkbox.
Click Apply or OK for your changes to take effect.
In android studio Go to setting menu > Built,Execution and development option > Gradle > mark/unmark on your offline work option and sync your project.try this.

Gradle build get stuck after update android studio to 2.1.3 version

before updating android studio, my gradle version was 2.10 and gradle plugin version was 2.1.0 and every things work fine. Unfortunately after updating android studio and android gradle plugin to 2.1.3, android studio can't build project and get stuck in gradle build running!
this is my project build.gradle code snippet:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
and currenly my gradle version is 2.14.1. thanks for help.
I had this problem before. It seems your gradle works in online mode. you must switch it to offline mode. In Android Studio open the settings and search for offline. in the Gradle sub category and Global gradle settings section, you will see Offline work check box.check it to force gradle works offline.
good luck.
this way worked for me :
delete .gradle folder in your project folder
make sure that your system proxy is enable(for iranian user!)
enable Auto-detect proxy setting at :
File > Settings > Appearance & Behavior -- System Settings -- HTTP Proxy
Go to gradle.properties file (project root directory) and add these options (for both http and https):
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=user
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=localhost
systemProp.http.auth.ntlm.domain=domain
systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=user
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=localhost
systemProp.https.auth.ntlm.domain=domain
but i config this form(because i use psiphon)
systemProp.http.proxyHost=127.0.01
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=8080
make sure that your gradle not be in offline mode then select use default gradle wrapper... in :
File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
Now Sync Project with Gradle Files
I hope that I have helped

Android Studio installation doesn't work with gradle

I am absolute beginner with Android Studio (especially Gradle) and having big trouble getting Android Studio to work. I downloaded and installed the most recent version of Android Studio (0.8.0). I have set the JDK_HOME variable. However, after I create a new project, I always receive the following message:
Error:Unknown host 'jcenter.bintray.com'.
Enable Gradle 'offline mode' and sync project.
Learn about configuring HTTP proxies in Gradle
If I try to compile the project, I get the following message dialog:
After reading a post, I manually downloaded the Gradle binaries (latest, 2.0), extracted it onto the local drive, went to Settings and set the Gradle path to the respective directory using the following:
I also tweaked the build.gradle file under the project to point to the latest Gradle 2.0 version. However, now I get the following error message:
Error:A problem occurred configuring root project 'HelloAndroidStudio'.
Could not resolve all dependencies for configuration ':classpath'.
Could not resolve com.android.tools.build:gradle:2.0.+.
Required by:
:HelloAndroidStudio:unspecified
Failed to list versions for com.android.tools.build:gradle.
Unable to load Maven meta-data from http://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml.
Could not GET 'http://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml'.
jcenter.bintray.com
Please can someone help. Being my first time with Gradle, I have been trying for so many days without any clue to the problem. Thanks.
Change the Gradle version to lower ones and restart the Android Studio, you may get it.
Add this in build.gradle
classpath 'com.android.tools.build:gradle:1.1.0'
Setting the http_proxy under appearance & behaviour -> system settings -> http proxy has solved the problem
Change to the latest classpath in the dependencies.
For AS 1.5.1 I will do like this :
buildscript {
repositories {
jcenter()
}
dependencies {
**classpath 'com.android.tools.build:gradle:1.5.0'**
}
}

Android Studio Gradle Download Error

When I load Android Studio, I get an error
Gradle 'HelloWorld' project refresh failed
Error:Could not download artifact 'com.android.tools.build:builder-model:0.12.1:builder- model.jar': No cached version available for offline mode
Not only this but Android Studio takes a long time to load a project; stuck on Gradle Resolve Dependencies.
I am on Windows 8.1 and using JDK 8
How would I fix this?
You probably have Android Studio configured to use Gradle in offline mode, and it's failing because it lacks dependencies that it needs to download. Make sure your computer has internet connectivity, and in Preferences > Gradle > Offline work, make sure that setting is unchecked.
For Android Studio 3.3.2 -
Open File > Settings > Gradle > (unchecked) offline work on Global Gradle Setting.
Make sure that you have internet connection and try to sync your project more (or File > Sync project with gradle files).
the simplest solution is -
click file > project structure > Gradle Setting >
now check if your "Gradle user Home" field is empty if it is . then enter the path of your gradle.
your gradle should be stored in
C > users > .gradle
copy the path and enter it here and now click on gradle build button on top right in your android studio.

Categories

Resources