Cause: buildOutput.apkData must not be null

2020-02-02 04:15发布

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

27条回答
爷的心禁止访问
2楼-- · 2020-02-02 05:06

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.

查看更多
beautiful°
3楼-- · 2020-02-02 05:06

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

查看更多
我只想做你的唯一
4楼-- · 2020-02-02 05:07

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.

查看更多
beautiful°
5楼-- · 2020-02-02 05:08

FOR Android Studio 3.5

debug builds finish without any error. During the 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 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 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

查看更多
家丑人穷心不美
6楼-- · 2020-02-02 05:09

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

查看更多
淡お忘
7楼-- · 2020-02-02 05:09

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

2- Delete the build folder

3- clean project

查看更多
登录 后发表回答