Android Studio: Gradle Build error, can't loca

2019-06-23 04:05发布

问题:

I am new user of Android Studio and I have serious problem with trying to import Android Studio project to Android Studio on other PC. In general, my Gradle doesn't want to build the project and it is caused by problem with path.

Error log:

Failed to import Gradle project: Could not fetch model of type 'IdeaProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
Build file 'E:\Projects\MenuMenu\EventGame\build.gradle' line: 1
A problem occurred evaluating project ':EventGame'.
A problem occurred evaluating project ':EventGame'.
The SDK directory 'E:\Program Files (x86)\Android\android-studio\bin' does not exist

My Android-Studio SDK is in directory:

E:\Program Files (x86)\Android\android-studio\sdk

I found from various posts with similar problems that you can change path to sdk in local.properties file. Mine looks currently like that:

sdk.dir=

So it's empty, but still default path is SOMEHOW set to "E:\Program Files (x86)\Android\android-studio\bin" and I have no idea how to change it. If i try to add to sdk.dir real path the error is the same but the path in error looks like that.

The SDK directory 'E:\Program Files (x86)\Android\android-studio\bin"E:\Program Files (x86)\Android\android-studio\sdk"' does not exist

In 90% of causes I could find via the net people were solving the problem by adding: sdk.dir=/Applications/Android Studio.app/sdk

But then directory is set to E:\Program Files (x86)\Android\android-studio\bin\Applications\Android Studio.app\sdk and something like that doesn't exist in my PC.

Do you have any idea how to solve this problem. Is there any way to change this default path? I also get error:

E:\Projects\MenuMenu\EventGame\build.gradle
Gradle: A problem occurred evaluating project ':EventGame'.
> The SDK directory 'E:\Program Files (x86)\Android\android-studio\system\compile-server' does  not exist.

Thats how my folders looks like: https://www.dropbox.com/s/ikj63gmyfax8z4u/folders.png

回答1:

The easiest and imho the cleanest way to do this is not to set the directory by code, but with an enviroment variable in Windows:

  • Press Win + Pause Key together to see the system information
  • Click on Advanced systems settings (or similar..i don't know the exact english translation)
  • Select the Advanced Tab and on the bottom click on "enviroment variables"
  • Another window pops up where you click on the "New..." Button in the lower half of the window (The system variables area)
  • Name the Variable ANDROID_HOME and paste the path to your SDK as value (in your case E:\Program Files (x86)\Android\android-studio\sdk)
  • save and close everything

If you have a command line window open then close this as well and reopen cmd.exe if you want to use ANDROID_HOME within the command line.



回答2:

Okay in general problem was caused by the fact that the project was imported from Android-Studio installed on Mac. The slashes were in oposite direction, and somehow program couldn't override default direction because he couldn't understand the path.



回答3:

On the bottom right there is a display type icon, click on that then click gradle on the left side, then refresh it by clicking on the icon. You should have net connectivity. It will download a small file, about 50kb. This works for me.