Cause: buildOutput.apkData must not be null

78,673

Solution 1

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'

Solution 2

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.

Solution 3

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

Solution 4

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...

Solution 5

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

Share:
78,673

Related videos on Youtube

jzelar
Author by

jzelar

Updated on February 16, 2022

Comments

  • jzelar
    jzelar about 2 years

    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)
            ...
    
    • Eugen Martynov
      Eugen Martynov about 5 years
    • Andrew
      Andrew about 5 years
      I have the same after I updated Android Studio to 3.4
    • Nicky
      Nicky about 5 years
      Check Lemberg answer that works for me, I've faced that issue today
    • Patapoom
      Patapoom over 4 years
      Same for Java (not necessary Kotlin) after installing Android Studio 3.5.
  • kikoso
    kikoso about 5 years
    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)
  • luckyhandler
    luckyhandler about 5 years
    Also works for classpath 'com.android.tools.build:gradle:3.4.0-rc02'
  • void.pointer
    void.pointer about 5 years
    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.
  • devgianlu
    devgianlu about 5 years
    This is the equivalent of cleaning the project.
  • Roman Nazarevych
    Roman Nazarevych about 5 years
    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.
  • Martin Pfeffer
    Martin Pfeffer about 5 years
    @void.pointer why not? I'm on canary (also for production) for years. Can't complain about stability or bad performance (using macOS)..
  • Rafael
    Rafael about 5 years
    Works on Android Studio 3.4
  • 林果皞
    林果皞 about 5 years
    In my case I need to generate first product flavor apk (debug to release) to last flavor (debug to release).
  • Doongsil
    Doongsil almost 5 years
    Yes!! It worked for me too. thanks. I don't know why but it looks like a bug.
  • Hari
    Hari almost 5 years
    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 working
  • babay
    babay almost 5 years
    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.
  • VIISHRUT MAVANII
    VIISHRUT MAVANII over 4 years
    @babay 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.
  • Mihodi Lushan
    Mihodi Lushan over 4 years
    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 me
  • Mihodi Lushan
    Mihodi Lushan over 4 years
    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 me
  • Mihodi Lushan
    Mihodi Lushan over 4 years
    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 me
  • Mihodi Lushan
    Mihodi Lushan over 4 years
    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 me
  • Mihodi Lushan
    Mihodi Lushan over 4 years
    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 me
  • Suresh Maidaragi
    Suresh Maidaragi over 4 years
    Can you try File > Invalidate caches/Restart after delete auto-generated files .gradle and build @MihodiHasanLushan
  • Martin Pfeffer
    Martin Pfeffer over 4 years
    @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?
  • Mihodi Lushan
    Mihodi Lushan over 4 years
    tried those, yes, I am getting this error. @MartinPfeffer
  • ghita
    ghita over 4 years
    @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 windows10
  • Loadeed
    Loadeed over 4 years
    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'
  • solo
    solo over 4 years
    In my case: AndroidStudio3.5, Build bundle(s)/apk(s) => Build apk(s), then Generate Signed APK
  • Patapoom
    Patapoom over 4 years
    Works on Android Studio 3.5.
  • javaxian
    javaxian over 4 years
    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.
  • cVoronin
    cVoronin over 4 years
    It is crazy, but this solution works - I don't understand why. Android Studio 3.5, Windows
  • Apparao Mulpuri
    Apparao Mulpuri over 4 years
    Its a bug in Android Studio 3..5
  • james
    james over 4 years
    i got this error after step 3. APT: error: resource android:attr/fontStyle not found.
  • VIISHRUT MAVANII
    VIISHRUT MAVANII over 4 years
    @james 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 > assembleDebug
  • james
    james over 4 years
    I really appreciate your solution. Thanks. This is just simple and just really stupid build error of Android Studio.
  • james
    james over 4 years
    @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.
  • Vijay Kumar Kanta
    Vijay Kumar Kanta over 4 years
    Wow, you saved my life with this. However is this a bug in Android Studio or is my project messed up?
  • Shubham Jain
    Shubham Jain over 4 years
    @ Vijay Kumar Kanta this is an issue with the studio I hope in the new update it will be fixed
  • Henrique Monte
    Henrique Monte over 4 years
    OMG, this Android Studio upgrade to 3.5 brings a lot of issues for me.
  • buncis
    buncis over 4 years
    'Destination Folder' is a field in Generate Signed Bundle or APK modal;
  • dodgy_coder
    dodgy_coder over 4 years
    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)
  • Juan José Melero Gómez
    Juan José Melero Gómez over 4 years
    I only had to clean since my gradle version was 3.5.1 when I updated my project fro my repo.
  • CodeFluid
    CodeFluid over 4 years
    Very useful in Android 3.5.2
  • mkasberg
    mkasberg over 4 years
    I can't believe the working solution to this problem is actually "Change the destination folder." But it is! ¯\_(ツ)_/¯
  • Billyjoker
    Billyjoker over 4 years
    i do not know where is suppossed to change that directory. I have not figured out yet
  • VIISHRUT MAVANII
    VIISHRUT MAVANII over 4 years
    @Billyjoker 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.
  • Nuwan Withanage
    Nuwan Withanage over 4 years
    Within 3.5.3, 'Change the destination folder' not supporting due to studio already disabled the change option of destination
  • VIISHRUT MAVANII
    VIISHRUT MAVANII over 4 years
    @NuwanWithanage I have another solution & it may help you. try to generate debug signed build first then generate release signed.
  • Divakar Murugesh
    Divakar Murugesh about 4 years
    Thanks & Nice solution. I updated Android Studio even this error occurs in Android Studio 3.6. This solution saved my day. Thanks again
  • Wilmer
    Wilmer almost 4 years
    Also works for classpath 'com.android.tools.build:gradle:3.5.3' Android Studio 3.6.3
  • Farid
    Farid over 3 years
    You can't generate "Signed debug APK"
  • Dita Aji Pratama
    Dita Aji Pratama over 3 years
  • Pipin Indrawan
    Pipin Indrawan about 3 years
    thanks for the solution my app has hundred to thousand c++ class so cleaning will consume time.