18

I was trying to add a dependency to my application and I accidentally modified the wrong build.gradle file and now my application no longer builds correctly.

This is my error:

Error:FAILURE: Build failed with an exception.

* What went wrong:
Task 'generateDebugSources' not found in project ':app'.

* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I was trying to implement the code that exists here, but I ended up breaking things in Android Studio because I am new to the gradle system.

The files I edited were .idea/gradle.xml and build.gradle, which I am including below:

build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

gradle.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        <option name="distributionType" value="DEFAULT_WRAPPED" />
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="modules">
          <set>
            <option value="$PROJECT_DIR$" />
            <option value="$PROJECT_DIR$/app" />
          </set>
        </option>
      </GradleProjectSettings>
    </option>
  </component>
</project>

I was trying to get as close as the default files are, but ended up making the problem worse and I cannot build my project anymore.

Also, I am using Android Studio 1.1.0, which is shown to be the latest update.

Thanks in advance, and if I need to provide more information, just let me know.

1
  • All I did was changing something (i.e. deleting some character) in app's build.gradle file, and syncing project as suggested after gradle change.
    – Dimmy3
    Nov 24, 2017 at 10:55

9 Answers 9

47

Not mentioned here, so maybe it can help some people. Got this error and solved it by doing a gradle sync (somehow, android studio was not suggesting it).

4
  • you saved me :)
    – Rajesh N
    May 7, 2018 at 14:54
  • been doing a clean or rebuild project, syncing the gradle fixed it for me as well. thanks!
    – sticky
    Nov 14, 2018 at 16:35
  • just edited and then un-edited the gradle, and synced it was the fix for me.
    – Arpit J.
    Mar 25, 2019 at 7:28
  • Thank you for that little gem! Aug 8, 2019 at 21:01
17

In Android Studio menu: Go to File -> Invalidate caches / restart

IMPORTANT NOTE: Take into account that it will also clear "Local History" if it's important to you.

1
  • Unfortunately this didn't help.
    – azizbekian
    Sep 11, 2018 at 13:13
3

Check your settings.gradle. Your module gradle has to be include in your settings.gradle.

include ':app'

You must to change that include for the name of the module of your application. If not, try to remove that include, and restart the Android studio :)

0

Chris Deligan got it partially right.

Basically, you need to resolve the gradle dependencies so that Android Studio can correctly recognize that a generateDebugSources task does indeed exist in your :app (For me it was the other way around - I needed Android Studio to recognize that generateDebugSources does not exist).

Doing an include ':app' did resolve the problem for me, but that's because gradle wasn't resolving the dependencies earlier properly for me. Doing an include ':app' and rebuilding the project helped because Studio rebuilt those dependencies properly because of it. (Oh and removing it helps as well)

========================================================================

IN Brief -

Do something that re-generates the dependencies. Ways to do that are:

  1. include :app - Add or remove this from your project gradle file and do a rebuild.
  2. gradle init - Running this from the terminal helped.
0

I had this same issue and luckily I had made a recent backup and I figured out that the build.gradle file was missing from the App Folder. I copied that back into my project under the /AppName/app/build.gradle and the error went away.

apply plugin: 'com.android.application'


android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.company.appname"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 25
        versionName "2.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile project(':BaseGameUtils')
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.google.android.gms:play-services-plus:10.0.1'
    compile 'com.google.android.gms:play-services-ads:10.0.1'
    compile 'com.google.firebase:firebase-ads:10.0.1'
}
apply plugin: 'com.google.gms.google-services'
0

I faced the same problem. This error occured because I unknowingly deleted the app build.gradle file ,so I created a new build.gradle file in my app directory and placed all the required code there then synced this file .The project successfully build after this.

0

Happened to me as well because I changed the build variant in another branch and that change took over in all other branches. Hence, what I did was:

  1. Clean
  2. Rebuild
  3. Invalidate cache and Restart (just to make sure it work)

And the problem is gone and resolved for all the branches.

PS - whenever you want to change the branches, do not allow to take over the other branch's changes. Otherwise, you will have to repeat this process for current branch as well.

-1

Had the same problem and fixed it by updating TO latest build-tools version:

buildToolsVersion '24.0.1'

OR

buildToolsVersion '24'
-9

I fixed my issue; I discovered that new projects didn't have the issue with the gradle, so I made a new project and transferred all my src code files and it works fine again.

2
  • Do you know why this happens? Dec 15, 2015 at 11:34
  • This didn't work I also don't know why this would work for you only and not others. Glad it fixed your problem but we are still seeing the issue.
    – Elliott
    Jun 20, 2018 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.