270

I am trying to run a selected build variant but giving me following error in Run tab,

Unable to determine application id: com.android.tools.idea.run.ApkProvisionException: No outputs for the main artifact of variant: madhyapradesh-debug

So kindly suggest the solution to it.

shizhen
  • 12,251
  • 9
  • 52
  • 88
RAHUL UMAK
  • 2,721
  • 2
  • 12
  • 7
  • 14
    I wonder why every Android Studio update is so painful. I prefer to keep existing version as long as possible because of this. – Boogier Dec 14 '20 at 06:27

26 Answers26

351

First clean your project by

Build -> Clean project

Then rebuild project

Build -> Rebuild project

Then run your project. I hope this will work.

if not then go to

File -> Invalidate Caches / Restart -> Invalidate and restart

The last option is you can sync Gradle again in case nothing worked

You Qi
  • 8,353
  • 8
  • 50
  • 68
Mirza Ahmed Baig
  • 5,605
  • 3
  • 22
  • 39
145

Your Gradle is out of sync. Go to: File -> Sync Project with Gradle Files. It should fix the problem.

enter image description here

Boken
  • 4,825
  • 10
  • 32
  • 42
kadepeay
  • 1,551
  • 1
  • 4
  • 3
  • 9
    Pressing shift twice, searching ```sync gradle``` then pressing enter do the same stuff if you are lazy to move the cursor by mouse or touchpad. – firemaples Apr 13 '21 at 02:33
83

This is because your gradle version in project build.gradle configuration is too old for a newer Android Studio version, like Android Studio 3.6.1,

1. you should change the gradle configuration into a newer one under: build.gradle(project)->buildscript->dependencies->classpath;

for example, you should change:

classpath 'com.android.tools.build:gradle:2.3.1'

into:

classpath 'com.android.tools.build:gradle:3.1.2'

2. after this, may be you should also change the configuration in gradle-wrapper.properties into a newer version, for example, change:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

into:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

3. after this, may be you should also add google() at:

build.gradle(project)->buildscript->repositories

and

build.gradle(project)->allprojects->repositories

applixy
  • 873
  • 6
  • 5
  • 1
    Update the classpath in the Project build works for me.Thank you! – Bruce Sep 26 '20 at 03:32
  • 1
    After updating my gradle versions, I had to also `Sync Project with Gradle Files` to have it work. Thanks!! – Eric Nov 16 '20 at 23:23
  • But shouldn't be this applicable to all the projects. I find this strange incase of 2 project with same Gradle and build tool plugin projects for 1 it is working fine and for other suddenly started throwing error for last 2 weeks, before that it was working fine. – Shadow Droid Jan 05 '23 at 07:31
  • They talk about 'gradle version' and 'plugin version'? Is distri-url->plugin and classpath->gradle? Or vice verca? See link: https://developer.android.com/studio/releases/gradle-plugin I want to know the latest versions. – Jomme Jan 20 '23 at 21:47
29

I faced this problem today.

Select nothing from the installation option and click on the add icon button. Select Run Gradle task. enter image description here

Double click on the run Gradle task and there will be a pop-up option like the image. Change the first option to the app and the second option to install debug like the image.

Now finally you solved the problem

enter image description here

Boken
  • 4,825
  • 10
  • 32
  • 42
Shaon
  • 2,496
  • 26
  • 27
27

I have the same issue with a Cordova Project after I updated Android Studio to 3.6.1

As a workaround (at least for the first installation of the app) I use installDebug Gradle Task from Gradle Tab View -> Tasks -> Install

enter image description here

Liviu
  • 768
  • 8
  • 9
  • 1
    this fix the problem I had with my LibGdx game. Thx! – b3nk4n Mar 29 '20 at 16:29
  • My computer's power was disconnected due to an electricity issue while I was working on an android project. So I started facing this issue after that. Your answer solved my problem. Thanks! – Zaif Senpai Jun 10 '21 at 00:26
14

For me doing:

File -> Invalidate Caches / Restart

worked fine ^^

Z3R0
  • 1,011
  • 10
  • 19
9

For me the solution was apparently to update the Gradle plugin...

Guillaume
  • 477
  • 5
  • 6
8

Workaround 1

Create a new configuration for Run with the same parameters as the default config app. This work for me.

  1. Run
  2. Edit Configuration
  3. Add New Configuration (NOT COPY) -> Android App
  4. Rename
  5. Choose app Module
  6. Apply

Workaround 2

  1. Use the task for install in Gradle Tab View -> Tasks -> Install
  2. Run the app.

Workaround 3

  1. Delete .gradle folder
  2. Invalidate Caches / Restart ...
  3. Run the app
Braian Coronel
  • 22,105
  • 4
  • 57
  • 62
6

I faced this problem today.

Select "Default APK" from the installation option and click on the add icon button. Select "Gradle-aware Make"->"OK" enter image description here

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
4

Sometimes a gradle sync and run will do the job. I was facing this after gradle plugin update too. Gradle sync might not have happened sometimes.

Shangeeth Sivan
  • 2,150
  • 1
  • 20
  • 20
4

Do follow the three steps:

  1. Clean project: Build(menu) >> Clean Project
  2. Sync project: File(Menu) >> Sync Project with Gradle Files
  3. Rebuild project: Build(menu) >> Rebuild Project

Now run your app and enjoy.

Subarata Talukder
  • 5,407
  • 2
  • 34
  • 50
4

First clean your project and then rebuild the project it will solve the problem

Yazdan Ilyas
  • 374
  • 4
  • 8
3

Set Deploy to NOTHING worked for me. (kudos to above nvatvm above)

enter image description here

enter image description here

jim
  • 228
  • 4
  • 10
  • 3
    I believe this will just run the application, but without updating it. At least if it's not an instant app. – Velda Aug 14 '20 at 13:57
3

First of all Clean Project and Rebuild Project. If it doesn't work then the Easy, Hardcore, Fast approach which works for me was just deleting the two following folder named .gradle and .idea after closing the IDE and restart it -

enter image description here

Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42
2

Ensure that your have set applicationId "com.example.myapp" in your build.gradle

android {
    ...
    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    ...
}

And from app -> Edit Configurations, ensure that you have selected "Default Activity"

shizhen
  • 12,251
  • 9
  • 52
  • 88
2

Project Structure - Suggestions - Update Gradle

2

Try running the following command on the Android Studio Terminal:

  • gradlew connectedAndroidTest
Cherif Diallo
  • 311
  • 2
  • 3
2

The other answers are not working for me. The only solution that worked for me was to delete .gradle and .idea folders.

Abhishek Dutt
  • 1,308
  • 7
  • 14
  • 24
test
  • 21
  • 1
  • I tried all the soludion mentioned in below answers and comments. Neither those workaround or your mentioned work around is working for me :(. Also I noticed a strange a problem for another project with same Gradle and Android Gradle plugin version it is working fine. The project for which I got issue was working fine even after Android Studio update to Dolphin but suddenly past 2 week this issue occured. – Shadow Droid Jan 05 '23 at 06:32
1

My solution was to upgrade Android Studio from "Artic Fox | 2021.3.1 Canary 12" to "Artic Fox | 2021.3.1 Canary 13"

amp
  • 11,754
  • 18
  • 77
  • 133
1

You need to update the Gradle version: go to File -> Project structure, then update the Android Gradle Plugin version, and Gradle Version to the latest stable versions(now 7.0.2 & 7.2 respectively)

Omar Ahmed
  • 11
  • 2
  • 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](/help/how-to-ask). – Community Sep 21 '21 at 18:27
0

View Gradle Table => right click the application => click "Reload Gradle Project"

Chi
  • 188
  • 3
  • 10
0

Check if you have Build Variant selected: Go to Menu > Build > Select Build Variant

Select a build variant that ends with Debug for the Release Variants you need the signing certificate configured correctly.

RenRen
  • 10,550
  • 4
  • 37
  • 39
0

setting Installation Options-> Deploy: APK from app bundle worked for me.

0

Nothing worked for me like the clean build, rebuild and invalidate cache restart. Here's my solution to this problem.

The workaround was to delete the existing app configuration from Run/Debug Configurations. enter image description here

After that add new configuration by clicking the left top + icon and then add Android App.

enter image description here

Haris Bhatti
  • 191
  • 2
  • 9
-1

The answer by @applixy worked for me. 1.Just note to update the classpath to the latest version in project->build.gradle to

classpath 'com.android.tools.build:gradle:4.1.1'

2.And in the gradle->wrapper.proprties just apply sync with gradle upon distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip

3.My project already had the google() method on allprojects{}. So build your project and run you are good to go.

Manacy
  • 17
  • 3
-3

Error: Unable to determine application id: com.android.tools.idea.run.ApkProvisionException: No outputs for the main artifact of variant: debug

Solution : Go to:

  1. File
  2. project structure (Ctrl + Alt + Shift + S)
  3. Suggestions
  4. Update Graddle

Then wait for downloading griddle to solve your problem.

Boken
  • 4,825
  • 10
  • 32
  • 42