Home » Android » Android Studio new project can not run, throwing error

Android Studio new project can not run, throwing error

Posted by: admin April 23, 2020 Leave a comment

Questions:

Just now I have installed and started working on Android Studio, and created new project after configuring everything I needed to start working on project. In newly created project, I have not changed anything and then tried to run the project. But it is not working and throwing some dependency error I guess. Here is it

Gradle: 
 FAILURE: Build failed with an exception.
  • What went wrong:
    A problem was found with the configuration of task ‘:StudioTest2:packageDebug‘.

    File ‘C:\Users\StudioTest2\StudioTest2\build\libs\StudioTest2-debug.dex’ specified for property ‘dexFile’ does not exist.

  • Try:
    Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

    Could not execute build using Gradle distribution ‘http://services.gradle.org/distributions/gradle-1.6-bin.zip‘.

How to&Answers:

One thing I found that helped was to import the project after creating it, I was getting the same issue but once I imported the project (as opposed to just opening it), it built fine.

Answer:

Any of the following may work:

1) clean project
2) File -> invalidate caches/ restart.
3) Restart computer.
4) See if some other project is compiling but not the current one. Notice the difference between the two and modify things in the current project if required.

I have wasted my 5 hours on this error.

Answer:

Install Android Studio to the default installer location. Something like C:\Users\<user>\AppData\Local\Android\android-studio. When you run it create your project again.

Answer:

I did not want to use the AppData location to store the program (although that would work), and none of the other solutions worked.

What ended up working was simply using a path that did not have spaces for my Android Studio install location.

For example,
I was using:

E:/dev/Android Studio/

I then changed it to:

E:/dev/android-studio/

When I was using Fedora for development, applications compiled, and I noticed the application zip extracted to android-studio.
Furthermore, using running gradle packageDebug within my project directory on windows did not work, even with –stacktrace –debug.

Further observations: This problem might not have anything to do with android studio. It might just be that the sdk folder in android-studio needs to be in a path without spaces.

I am under the impression that this would work for people using an alternate sdk location without spaces in the path.

Finally, projects not using build.gradle imported from eclipse worked just fine. Only projects created in android studio using gradle refused to compile and returned the curious dexFile packageDebug error.

Gradle projects now compile. Hope this helps someone.

Answer:

This error because something is going wrong that must be take in knowlegde.

First of all download the gradle from this link

Then Extract it to anywhere in your PC.
After that Right click on My Computer icon –> Properties –> Advanced Setting –> Environment Variable –> System Variable

add the new path here like below.

Variable name : GRADLE_HOME.
Variable Value : path to your gradle.

After that run command promt then type gradle check that it properly works.

Set path to your Project root directory which content gradlew file.
After setting the path just type the folloeing command in your command promt.

gradle compileDebug

Hope this will helps you.

Answer:

Use your console to navigate to your project root directory where you will find gradlew script. run it with “compileDebug” option to see the exact error. There are other options to use as well, “gradlew help” will tell you more

Answer:

I request apologizes about my bad English.

The solutions proposed did not worked in my case, but I managed to solve it myself.

My scenario was the following: created a project in an XP computer with eclipse, imported it to android studio, then I commited it to my SVN repository.

Later, I downloaded it to another computer with Windows 7 and Android Studio, and I obtained the discussed error (debug.dex’ specified for property ‘dexFile’ does not exist).

I tried all the proposed solutions without sucess. What worked for me? Two steps:

  • first, correct the JDK path under “File->Project Structure->Project”. At computer number I had JDK_1.6_016 and at computer number 2 I have JDK_7.

  • second: deleted (you can rename it if you dont want to delete it) the file “local.properties” in the project folder. It was pointing to the Android SDK folder in the Windows XP path style (documents and settings and so on instead of “users”).

Then my project compiled with sucess.

Best regards.

Edited: better than deleting the file local.properties, edit it and correct the path to the android sdk file

Answer:

I seem to face this problem when I try to run the project in debug mode. Then it starts giving Gradle errors. I try the menu option “invalidate cache restart”, sometimes it works sometimes it doesn’t. I just close the android studio and try to run it after a while later, it works. I’m not sure what’s happening inside the software’s brain.

Answer:

What you need to do as Nick was saying on the comments above:

for windows users:
open cmd as administrator and run:

gradlew.bat packageDebug

for unix like os:

go to the root directory of the project and run:

sudo gradlew packageDebug

In case you are getting errors you are missing some repos from maven.org go to /Applications/Android Studio.app/sdk/tools or the the android studio directory on Program files, and run android in unix or android.bat on windows.

Answer:

i upgrade android studio from 0.3.1 to 0.3.2 and recreate project solved this problem.

Answer:

Updating to latest build tool and restarting studio fixed the issue for me

Answer:

Try this

Tools > Android > Monitor (DDMS included)

You will see SDK welcome message, and then go back to editor, and try to rebuild again.