Cause: buildOutput.apkData must not be null
Asked Answered
C

30

270

My android application using Kotlin is throwing this exception when I try to Run 'app' in the emulator o in my cellphone. When I build my project it runs well, with no errors.

I am using:

  • SDK 28 (Android 9.0 (Pie))
  • Gradle 5.1.1
  • Gradle Plugin 3.5.0-alpha03
  • Kotlin 1.3.10
  • Java 1.8.0_151
  • OSX 10.13.2
    org.gradle.internal.exceptions.LocationAwareException: buildOutput.apkData must not be null
        at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:99)
        at org.gradle.initialization.exception.DefaultExceptionAnalyser.collectFailures(DefaultExceptionAnalyser.java:65)
        at org.gradle.initialization.exception.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:39)
        at org.gradle.initialization.exception.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:29)
        at org.gradle.initialization.DefaultGradleLauncher.finishBuild(DefaultGradleLauncher.java:194)
        at org.gradle.initialization.DefaultGradleLauncher.finishBuild(DefaultGradleLauncher.java:141)
        ...
    Caused by: java.lang.IllegalStateException: buildOutput.apkData must not be null
        at com.android.build.gradle.internal.ide.EarlySyncBuildOutput$Companion$load$2.invoke(EarlySyncBuildOutput.kt:103)
        at com.android.build.gradle.internal.ide.EarlySyncBuildOutput$Companion$load$2.invoke(EarlySyncBuildOutput.kt:67)
        at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:174)
        at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:691)
        at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:721)
        at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:712)
        ...
Cohesive answered 3/2, 2019 at 13:24 Comment(4)
I created a ticket issuetracker.google.com/issues/129994596Episiotomy
I have the same after I updated Android Studio to 3.4Louvain
Check Lemberg answer that works for me, I've faced that issue todayBelligerent
Same for Java (not necessary Kotlin) after installing Android Studio 3.5.Gorgonzola
P
327

Click Build -> Clean Project

Then Build -> Make Project

Tested on gradle 3.5.0-alpha3, -alpha5 and 3.4.0 (project gradle)

classpath 'com.android.tools.build:gradle:3.5.0-alpha03'
Picasso answered 4/2, 2019 at 16:49 Comment(12)
I can confirm this is working as well with the version com.android.tools.build:gradle:3.5.0-alpha05 (with Build -> Rebuild Project in AS)Catheycathi
Also works for classpath 'com.android.tools.build:gradle:3.4.0-rc02'Veliger
Sadly it requires upgrading to Android Studio 3.5, I can't tell my team to switch to an unstable channel for Android Studio updates.Gaytan
@Gaytan why not? I'm on canary (also for production) for years. Can't complain about stability or bad performance (using macOS)..Picasso
Works on Android Studio 3.4Pagurian
trying on AndroidStudio3.5 on Mac OS, all sdk updated, using gradle version com.android.tools.build:gradle:3.5.0, this solution is not working for meGirand
@MihodiHasanLushan Delete the build folder and build project again. Otherwise check if your gradle is correct (sdk, dependencies, etc). Are you sure you are getting the same error message?Picasso
tried those, yes, I am getting this error. @MartinPfefferGirand
@MihodiHasanLushan for me it works only after i'ved run 'gradlew clean build' on android studio's terminal. i am using classpath 'com.android.tools.build:gradle:3.5.0' with android studio 3.5 on windows10Zeeland
Works on Android Studio 3.5.Gorgonzola
I only had to clean since my gradle version was 3.5.1 when I updated my project fro my repo.Rola
Also works for classpath 'com.android.tools.build:gradle:3.5.3' Android Studio 3.6.3Convulse
W
165

FOR Android Studio 3.5 | 3.6

debug builds finish without any error. Creating a signed .apk leads to the same error

buildOutput.apkData must not be null

the Simple solution that I found is. During the signing of the apk after entering the signing credentials when you navigate to the next screen then it will ask for the destination folder just change the default path.

Let's assume the current destination path is

c:\user\folder\project\app

change it to

c:\user\folder\project\

then it will generate the signed apk successfully.

Android studio destination folder screenshot

Womanlike answered 28/8, 2019 at 19:24 Comment(7)
I really appreciate your solution. Thanks. This is just simple and just really stupid build error of Android Studio.Clone
Wow, you saved my life with this. However is this a bug in Android Studio or is my project messed up?Sewer
@ Vijay Kumar Kanta this is an issue with the studio I hope in the new update it will be fixedWomanlike
OMG, this Android Studio upgrade to 3.5 brings a lot of issues for me.Wicket
Very useful in Android 3.5.2Afternoons
Thanks & Nice solution. I updated Android Studio even this error occurs in Android Studio 3.6. This solution saved my day. Thanks againTeamwork
thanks for the solution my app has hundred to thousand c++ class so cleaning will consume time.Insulin
N
162

For Android Studio 3.5 & 3.6 Update (APK signed issue)

Step 1: I have resolved this issue by modifying the Destination Folder location.

Before

c:\user\folder\project\app

After

c:\user\folder\project\apk

enter image description here

For Android Studio 3.4 Update.

Step 1: After update Android Studio 3.4 you need to add all the dependency that used in your module or library in your app-level build.gradle.

Step 2: Clean Project(Build > Clean Project)

Step 3: Rebuild Project(Build > Rebuild Project)

Now, Your Project will compile Perfectly.

Nimwegen answered 3/5, 2019 at 10:40 Comment(12)
what's that? what should I do exactly? > Step 1: After update Android Studio 3.4 you need to add all the dependency that used in your module or library in your app-level build.gradle.Renounce
@Renounce Suppose you are using any library that is using Glide library. Then you have to add your Glide dependency in your App level build.gradle also.Nimwegen
i got this error after step 3. APT: error: resource android:attr/fontStyle not found.Clone
@Clone I think there is a resource missing. follow the below steps to find an issue. Click on Gradle(You will find in Top-Right Corner) > app_name(root) > other > assembleDebugNimwegen
@VishrutMavani Thank for your answer, but i found the really stupid error of Android studio. I just changed the build output path. That is. Solution by Shuham Jain. See below his solution.Clone
'Destination Folder' is a field in Generate Signed Bundle or APK modal;Sharkskin
This fixed my issue in Android Studio v3.5 and a Java project. This is a pretty standard occurrence whenever building Android apps now ... (1) get a weird incomprehensible build error (2) google it (3) stack overflow (4) apply seemingly unrelated workaround in a specific order (5) pray (6) it works (7) go to step (1)Kymric
I can't believe the working solution to this problem is actually "Change the destination folder." But it is! ¯\_(ツ)_/¯Blackout
i do not know where is suppossed to change that directory. I have not figured out yetPaling
@Paling During the signing APK after Entering the signing credentials when you navigate to the next screen then it will ask for the destination folder. just change the default path.Nimwegen
Within 3.5.3, 'Change the destination folder' not supporting due to studio already disabled the change option of destinationSkedaddle
@NuwanWithanage I have another solution & it may help you. try to generate debug signed build first then generate release signed.Nimwegen
D
53

I was getting this error also, when trying to "Generate Signed APK" for my release version. I tried all of the above methods, unfortunately none worked for me.

What worked, was generating first the debug signed version of the app, and then generating again the release one.

I do not know what exactly changed or what the original problem was, but it worked. I hope it will help you too, because this error is quite annoying...

Darrondarrow answered 30/4, 2019 at 18:6 Comment(6)
In my case I need to generate first product flavor apk (debug to release) to last flavor (debug to release).Incrocci
Yes!! It worked for me too. thanks. I don't know why but it looks like a bug.Dromous
trying on AndroidStudio3.5 on Mac OS, all sdk updated, using gradle version com.android.tools.build:gradle:3.5.0, this solution is not working for meGirand
In my case: AndroidStudio3.5, Build bundle(s)/apk(s) => Build apk(s), then Generate Signed APKAnne
It is crazy, but this solution works - I don't understand why. Android Studio 3.5, WindowsSpano
Its a bug in Android Studio 3..5Leonardo
J
23

Cleaning the project didn't help me but manually deleting all the auto-generated build folders in all modules helped. enter image description here

Junction answered 18/4, 2019 at 16:11 Comment(4)
This is the equivalent of cleaning the project.Audio
No, it isn't, try to clean project from Android Studio and then check App directory for build directories in any file explorer, you will see that some files are still left there.Junction
In my case I had multiple flavours, it worked once I had deleted all the build folder along with Flavour specific folders. After deleting folders, I had to close the project and reopen to get it workingHalfpint
trying on AndroidStudio3.5 on Mac OS, all sdk updated, using gradle version com.android.tools.build:gradle:3.5.0, this solution is not working for meGirand
B
18

Updating to Android Studio 3.4.?, i get the message

Cause: buildOutput.apkData must not be null

looking for an answer i found the procedure:

Build -> Clean Project

but it doesn´t worked, i know that this procedure will delete the content into the /build directory but for my experience it doesn´t work in all cases, so i tried the "raw" way, deleting the directory:

/app/build/ 

then i rebuild the project and it worked.

Brett answered 18/6, 2019 at 21:30 Comment(1)
This worked for me, but I had to also remove all <flavor>/<buildConfig> directories (it's about output.json files in them). Clean project alone didn't solve the issue.Margarine
S
9

All the solutions didn't work with me

Android Studio V 3.5

Android gradle plugin V 3.4.2

Gradle Version V 5.1.1

  1. Clean the project
  2. Restart Android Studio + Invalidate Caches
  3. Delete the build, debug, and releases folder
  4. Make project
  5. Generate signed APK

Reference

Sherr answered 28/8, 2019 at 0:39 Comment(0)
H
9

I tried above multiple solutions but nothing has happened then I found this this and worked for me

    deleting debug/output.json and release/output.json solved my problem

Now I am able to generate apk

Honorarium answered 8/10, 2019 at 13:6 Comment(0)
B
7

I've tried many things to solve the issue, but nothing helped. I get this error when trying to generate a signed apk.

Downgrading to older versions of Android Studio helped (3.4.2) worked, however this is not the solution.

The 'Clean Project' function in AS does not clean the place where your generated apk is created and there is one file that may be blocking the whole procedure: output.json

Try removing output.json from .../app/projectname/release/output.json

Baskett answered 22/8, 2019 at 9:34 Comment(0)
H
5

I was using Android Studio 3.5 beta 2 and I was having the exact same error but only on my release build. After trying every other solution I found, the only way I was able to compile again was to go back to Android Studio 3.4.

Hyperon answered 28/5, 2019 at 16:1 Comment(1)
This "solution" also worked for me. Downgrade to AS 3.4.2, downloadhere: developer.android.com/studio/archive and changing from 3.5.0 to: classpath 'com.android.tools.build:gradle:3.4.2'Tryst
L
4

It works for me:

  1. delete build folder from your project manually.

  2. in terminal of android studio type this command

if windows user

gradlew clean build

if linux user

./gradlew clean build
Legit answered 7/5, 2019 at 11:38 Comment(1)
trying on AndroidStudio3.5 on Mac OS, all sdk updated, using gradle version com.android.tools.build:gradle:3.5.0, this solution is not working for meGirand
S
4

This issue is happens usually when you are running multiple android studio window with different projects.

The solution is

  • choose project than delete .gradle and build folders
  • than clean and rebuild the project.

please ref screen shot attached

please ref screen shot attached

Septi answered 21/8, 2019 at 15:42 Comment(2)
trying on AndroidStudio3.5 on Mac OS, all sdk updated, using gradle version com.android.tools.build:gradle:3.5.0, this solution is not working for meGirand
Can you try File > Invalidate caches/Restart after delete auto-generated files .gradle and build @MihodiHasanLushanSepti
D
4

Just change the Apk release/debug location.

EX:

/home/sanaebadi/Desktop

after change :

/home/sanaebadi/apk
Denims answered 13/10, 2019 at 20:8 Comment(0)
P
3

the only solution that works for me is using in my root gradle

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

what i've tried : - clear all build folder manually - invalidate cache but none of these is work

PS: i'm using android studio 3.5 btw

Update :

just like @Vishrut Mavani, changing the destination folder of your release version is work

Polygynous answered 22/8, 2019 at 3:17 Comment(0)
A
3

The solution for me was to delete all files and folders from the apk output folder. I had this problem when creating a signed apk for a "production" flavor and the output.json in the "feature" output folder causes the problem -> Android Studio 3.6 Canary 7 showed me the correct error message. It is also working now for AS 3.5 stable with Gradle Plugin 3.5.0.

Architect answered 27/8, 2019 at 8:52 Comment(0)
O
3

All the solutions didn't work with me
In my case from AndroidStudio 3.4+ update to 3.5.
And finally I solve it by modify 'Destination Folder' to "app/build/outputs/apk"
detail pic

Orangeism answered 28/8, 2019 at 9:23 Comment(0)
C
3

The solution :-

1- Build -> Clean Project didn't help

2-Build -> Make Project didn't help

3- restart android studio didn't help

4- Manually remove Build folder from app and project didn't help

the only solution for me was to remove all old builds from destination folder

Cloninger answered 7/5, 2020 at 21:7 Comment(0)
A
2

Manually delete all the exiting build variant folder as well build folder in project folder worked for me.

Apostrophize answered 21/10, 2019 at 17:0 Comment(0)
C
2

Usually this issue happen on updating android Studio V3.4 to V3.5. Try to delete debug/output.json and release/output.json files.

Then Try these steps:

Step 1: Clean Project(Build > Clean Project)

Step 2: Rebuild Project(Build > Rebuild Project)

Crusted answered 22/10, 2019 at 5:29 Comment(0)
G
2

I have android studio 3.5.1 . For me below steps are worked

  1. File -> Invalidate Caches/Restart
  2. After android studio restarted click on Build -> Clean project
  3. Then Build -> Rebuild Project
Galla answered 5/11, 2019 at 7:12 Comment(0)
F
1

In my case build and launch project with different build configs was successful. But generating signed apk throws error Cause: buildOutput.apkData must not be null on the other hand apk was generated and Build Output toggle view prints BUILD SUCCESSFUL. Manual installation ends with message App not installed. My fault was using compileSdkVersion 'android-P' and after changing to compileSdkVersion 28 all goes well.

Flavorous answered 27/6, 2019 at 12:31 Comment(0)
P
1

I've tried all solutions and non of them helped! finally after many trying, I figured it out, just follow the tips:

  1. copy your signature keystrok (that you use to release) inside yourProject/app/
  2. gradle.properties (modify values related to your own key):
    MYAPP_RELEASE_STORE_FILE=KEYSTROK_NAME
    MYAPP_RELEASE_KEY_ALIAS=KEY_ALIAS
    MYAPP_RELEASE_STORE_PASSWORD=R_PASS
    MYAPP_RELEASE_KEY_PASSWORD=K_PASS
    android.enableR8=true
    
  3. app level build.gradle (inside android):

    signingConfigs{
        release{
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    
    configurations {
        cleanedAnnotations
        compile.exclude group: 'org.jetbrains' , module:'annotations'
    }
    
    
  4. app level build.gradle (inside buildTypes):
    release {
        manifestPlaceholders = [analytics_deactivated: "false"]
        minifyEnabled true
        signingConfig signingConfigs.release
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    

    5. finally this command:

mac: ./gradlew clean assemble_YOUR_FAVOR_Release

win: gradlew clean assemble_YOUR_FAVOR_Release

where _YOUR_FAVOR_ is your optional favor, if you are not using any favor, just simply use assembleRelease instead of assemble_YOUR_FAVOR_Release

Philibeg answered 25/8, 2019 at 4:40 Comment(0)
S
1

This issue happens after update my Android studio v3.4 to v3.5 Now, it is working fine

I fixed this issue by deleting debug/output.json and release/output.json files

Android Studio 3.5 compilesdkVersion 28

apk generating working

Sinking answered 6/9, 2019 at 13:46 Comment(0)
M
1

I was also annoyed by the same bug. But changing my Signed apk destination from c/users/project/app to c/users/project worked for me.

Matrass answered 7/9, 2019 at 16:34 Comment(0)
V
1

1- Delete all generated app bundles (.aab) and APKs for all variants.

2- Delete the build folder

3- clean project

Videogenic answered 20/10, 2019 at 11:47 Comment(0)
I
1

Generate Signed APK for debug, and then you can generate signed APK for release.

Increase answered 22/10, 2019 at 4:53 Comment(2)
You can't generate "Signed debug APK"Suckerfish
You can sign your debug build developer.android.com/studio/publish/app-signing#debug-modeIncrease
R
0

Seems cleaning the project may resolve the issue, but for me it worked like this.

File->sync project with gradle files.

Rambo answered 16/7, 2019 at 6:48 Comment(0)
M
0

AS 4.0.1 (installed via snap)

Ubuntu 18.04 lts

configuring builds via build variant.

Combinations of invalidate cache / build / clean etc didnt help on their own, the only thing that helped was to switch build the active build variant back to armDebug and clean / rebuild after that.

enter image description here

Once I switched back to the desired variant I could build correctly.

Manaker answered 28/9, 2020 at 11:4 Comment(0)
B
0

enter code hereIf your using different build variants, Select the specific folder to generate signin apk file. When you are trying to generate signin apk flow, you can change the path. For me, this worked.

Biliary answered 9/2, 2022 at 9:51 Comment(0)
L
0

In my case, the path was pointing to e: drive and other solutions didn't work for me. I did:

  1. Change the path
  2. The path must be in the c: drive

It solved the problem

Lee answered 25/11, 2022 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.