How do I resolve a “'generateDebugSources' not found in project” error?

前端 未结 8 1129
囚心锁ツ
囚心锁ツ 2021-02-07 07:36

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

相关标签:
8条回答
  • 2021-02-07 08:00

    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 讨论(0)
  • 2021-02-07 08:05

    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.

    0 讨论(0)
  • 2021-02-07 08:09

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

    buildToolsVersion '24.0.1'
    

    OR

    buildToolsVersion '24'
    
    0 讨论(0)
  • 2021-02-07 08:17

    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 讨论(0)
  • 2021-02-07 08:20

    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.

    0 讨论(0)
  • 2021-02-07 08:21

    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 讨论(0)
提交回复
热议问题