36

i am new to android development, i started developing from scratch on a project i bought online, following the documentation, i encountered a error saying No variants found for 'app'. Check build files to ensure at least one variant exists.

Here is the build.gradle code

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
    applicationId "com.app-10.app"
    minSdkVersion 23
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// Third Party Libraries
//Glide library for image fetching from the web
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//Material library for styling blocks
implementation 'com.google.android.material:material:1.0.0'
// Google Gson
implementation 'com.google.code.gson:gson:2.8.5'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
// Android-SpinKit
implementation 'com.github.ybq:Android-SpinKit:1.4.0'

implementation files('libs/YouTubeAndroidPlayerApi.jar')

// gotev/android-upload-service
implementation "net.gotev:uploadservice:3.5.2"

//A fast circular ImageView perfect for profile images
implementation 'de.hdodenhof:circleimageview:3.0.1'

implementation 'org.apache.commons:commons-io:1.3.2'

}
Stonz2
  • 6,197
  • 4
  • 45
  • 62
Deepak Marpak
  • 361
  • 1
  • 3
  • 3

6 Answers6

71

I have just solved the same issue like this:

Tools -> SDK Manager

Verify that the SDK platform package for Android 10.0 (the one with API level 29, like you defined in your gradle file) is checked. If not, check it and apply changes. Accept the licence terms, install the package and then File -> Sync Project with Gradle Files (or open the project again)

Fabio Rosati
  • 710
  • 2
  • 5
4

go to the SDK manager (Ctrl+Shift+A then write SDK manager), install the android version of current project, in this case I installed all the available options starting from 5.0

Supriyo Das
  • 101
  • 2
4

In my case, it is because I add flavourDimensions and not adding it to any productFlavors

example from my case I have in my build.gradle in app level:

flavorDimensions "stage", "mode"

and my productFlavors:

productFlavors {
    dev {
        dimension "stage"
        //noinspection DevModeObsolete
        minSdkVersion 21
        versionNameSuffix "-dev"
        applicationIdSuffix '.dev'
        resConfigs "en", "xxhdpi"
    }
    
    prod {
        dimension "stage"
        minSdkVersion 21
        versionNameSuffix "-prod"
        applicationIdSuffix '.prod'
    }
}

As you can see here, I don't use flavorDimensions "mode" in any of my productFlavors. So, when I try to sync my gradle. It gives me that error.

So my solution here is to remove "mode" from flavorDimensions

Fuad Reza
  • 111
  • 5
3

I replaced from:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

to my Android Studio v3.0.1 in my case:

dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

but at the end i resolve it by

you need to detect your proper sdk

you need to detect and set your proper sdk

my sdk is 30.0.2 after i install 29.0.2 this error gone

saber tabatabaee yazdi
  • 3,175
  • 3
  • 39
  • 52
2

Might help someone, in my case, I just needed to update Gradle.

A warning popped up on Android Studio, so I updated it, and then worked properly ‍♀️

coloboxp
  • 495
  • 9
  • 15
0

You may get the "No variants found" error in a project with multiple modules, when build types do not match between modules.

In my case, this happened when trying to add a macrobenchmark to an existing Android project. Following the instructions in this document, I added a new module macrobenchmark to the project. At some point, I misinterpreted the instructions: I added a new build type benchmark to the build.gradle of module app, but did not add the same build type to the build.gradle of module macrobenchmark. From then on, any attempt to sync the project with the gradle files would fail with the following error message:

No variants found for 'macrobenchmark'. Check build files to ensure at least one variant exists.

The solution was simple (but not trivial): bring the build types back in sync. In my case, add the missing build type benchmark to the build.gradle of module macrobenchmark.

Ruud Helderman
  • 9,692
  • 1
  • 24
  • 44