Android Studio: No build variant found error
Asked Answered
R

17

49

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'

}
Rimose answered 15/10, 2020 at 7:25 Comment(1)
Clean-rebuild at firstRedaredact
D
82

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)

Demp answered 22/10, 2020 at 16:2 Comment(3)
Installing API level 29 brought the Build Variant view back for me, no idea why it’s not a part of Android StudioSlade
For some reason, on Android Studio 2022.2.1 Patch 2, this did not work even though it was the correct solution. I had compileSdkVersion 29. In Tools > SDK Manager, I already had this "installed". It wasn't until I went into creating a new emulator, that the emulator complained I had no installed SDKs. Once I installed the SDK via Device Manager, my project ran again. So I was missing the SDK, it was just that Tools > SDK Manager was lying to me (or installing it in the wrong place, idk)Damselfly
@WillNasby I've found the same behaviour in my Android Studio right now - if you go to the installed SDK window it says they're all installed, yet when I went to the Emulators window it was already complaining of missing API 30. After installing it and checking the other SDKs (from the Emulator window) it was showing a bunch of them missing. The even annoying part is that this error doesn't say which one it's missing for you to only install that one (at least I didn't find any information).Wither
P
9

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's dimension. So, when I try to sync my gradle. It gives me that error.

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

Presentday answered 9/3, 2021 at 16:20 Comment(0)
C
6

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

Crankshaft answered 17/2, 2021 at 10:32 Comment(0)
B
4

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

Bikales answered 11/11, 2020 at 12:14 Comment(0)
C
3

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.

Calcifuge answered 27/12, 2021 at 12:27 Comment(0)
R
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 🤷🏻‍♀️

Rozanneroze answered 10/4, 2021 at 18:6 Comment(0)
C
2

For me the issue was that I hadn't opened the project at its root folder, I'd opened the "app" folder. Both folders had the gradle icon so it was an easy mistake to make after not having done any Android development for a while.

Chappelka answered 1/11, 2022 at 11:52 Comment(0)
P
2

The Gradle Sync always gives error No variants found for 'app'. Check build files to ensure at least one variant exists.

When running ./gradlew build It gives new error Installed Build Tools revision 31.0.0 is corrupted. and build-tool 31.0.0 is missing dx

So, if the SDK version is 31, that could be the error.

https://stackoverflow.com/a/68430992 fixed for me. The soln was to rename d8 to dx.

Presidentship answered 30/6, 2023 at 15:25 Comment(1)
In my case, the error was completely diferent that what Gradle Sync show to me. ./gradlew build was half life saver (other half have been used to find this solution). thanks (I hate my job)Kristof
A
1

In build.gradle file in dependencies section I changed

if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
    implementation jscFlavor
}

to

if (enableHermes) {
    implementation("com.facebook.react:hermes-engine:+") {
        exclude group: 'com.facebook.fbjni'
    }
} else {
    implementation jscFlavor
}
Anthropogenesis answered 12/5, 2023 at 18:12 Comment(0)
E
1

Here are few things you can check :

  1. Check API version required by app and the one that is installed. As stated by others in above answers.
  2. If there is any settings.gradle file or build.gradle, check if that needs any environment variables, if so feed the env variable on your system, or hardcode the env variable in settings.gradle file or build.gradle in order to run the code.
Ethnocentrism answered 12/10, 2023 at 13:18 Comment(0)
A
0

I had the same error, after an AGP upgrade, solded it by selecting arm64 in active ABI:build variant screenshot

No idea why that was on 'x86' after AGP upgrade.

Anodic answered 3/5, 2023 at 9:49 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Burch
D
0

I change gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

to

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip

build & install success

Drexler answered 21/5, 2023 at 11:7 Comment(0)
A
0

The key reason is that the gradle didn't recognize the application module (opposite to library module ect.) due to some errors in the build.gradle.

The solution is to find out what errors happened in the project build.gradle file.

  1. right click the abnormal module at the Android view.

enter image description here

  1. select the option [open module settings].

  2. check whether the module configuration is correct, including compile SDK version \ Build Tools Version \ Source Compatibility \ Target Compatibility.

enter image description here

  1. correct the configuration and manually sync again.

  2. ensure the compile SDK version has been downloaded to local from SDK manager.

Aromaticity answered 7/6, 2023 at 13:29 Comment(0)
C
0

For some reason, gradle throws such error when you are trying to import the jar file while there is no jar file or the "libs" folder itself.

Chancellorship answered 27/7, 2023 at 8:34 Comment(0)
E
0

tested:

  • gradle-7.3.3 + AGP-7.2.0: namespace "com.example.xxx" required for aar submodule in build.gradle.
  • gradle-6.7.1 + AGP-4.1.0: namespace "com.example.xxx" should be removed from aar submodule's build.gradle, while package "com.example.xxx" should be added to AndroidManifest.xml.
Esteban answered 6/1, 2024 at 7:2 Comment(0)
S
0

In my case I have enabled kotlin-kover library for test coverage, After creating build variants I forgot to change the report variant name so I got this error. Once I changed it to the available variant it worked. Previous it was

androidReports("debug") { .. }

then I changed to

androidReports("QADebug") { ... }

and it worked. Hope it helps!

Sylvanite answered 11/6, 2024 at 3:4 Comment(0)
T
-2

Try with

npm i [email protected]
Taxpayer answered 6/8, 2022 at 21:16 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.