Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New error after update to gradle-tool to 3.1.0-beta3 or 3.2.0-alpha03

Just a normal project with "prod" and "mock" flavors

in app/build.gradle:

 sourceSets {
        main.java.srcDirs += "blabla bla"
        test.java.srcDirs += "blabla bla"
        androidTest.java.srcDirs += "blabla bla"

        prodDebug.java.srcDirs += "blabla bla"
        mockDebug.java.srcDirs += "blabla bla"

        prod.java.srcDirs += "blabla bla"
        testProd.java.srcDirs += "blabla bla"
        androidTestProd.java.srcDirs += "blabla bla"

        mock.java.srcDirs += "blabla bla"
        testMock.java.srcDirs += "blabla bla"
        androidTestMock.java.srcDirs += "blabla bla"
    }

click "run" in Android Studio :

something goes wrong:

Error:org.gradle.api.GradleException: The SourceSet 'mockDebug' is not recognized by the Android Gradle Plugin. Perhaps you misspelled something?

However, I can do "./gradlew clean build" or "./gradlew assembleProd installProdDebug" etc.

But, if I do it in command-line, the app cannot be built completely, it can install the app on the target device, but the app will crash like "xxxx.dex" problem.

issue

like image 398
TeeTracker Avatar asked Feb 17 '18 23:02

TeeTracker


People also ask

What is latest Android gradle version?

Download the latest Gradle distribution The current Gradle release is version 7.5.1, released on 05 Aug 2022. The distribution zip file comes in two flavors: Binary-only.

What is gradle error?

Some of the Gradle files may get deleted unexpectedly. So when you will start building your apps you will get to see an error in Android studio as 'Error running android: Gradle project sync failed.

How do I check gradle updates?

Go to Android Studio -> Preferences -> Plugins (for Mac) and File -> Settings -> Plugins (for windows) and search “Check for Dependency updates plugin”. Install it and restart android studio. You will be able to see Dependencies tab on the right which will show if any dependency has a new update available.


1 Answers

Encountered the same problem after updating the Gradle Plugin from 3.0.1 to 3.1.0. Seems like Gradle now only finds the source set for the variant that is selected in Android Studio.

A workaround that fixes it for now is to remove the sourceSets {} block and add this instead:

def customSourceSets = [
    myFirstBuildVariant: 'src/myFirstBuildVariant',
    mySecondBuildVariant: 'src/mySecondBuildVariant',
]

android.applicationVariants.all { 
    if (customSourceSets.containsKey(name)) {
        sourceSets.find { it.name == name }.setRoot(customSourceSets.get(name))
    }
}
like image 186
saschoar Avatar answered Oct 01 '22 23:10

saschoar