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 04:52

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

查看更多
甜甜的少女心
3楼-- · 2020-02-02 04:53

For Android Studio 3.5 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


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.

查看更多
戒情不戒烟
4楼-- · 2020-02-02 04:53

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
查看更多
Deceive 欺骗
5楼-- · 2020-02-02 04:54

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

查看更多
Animai°情兽
6楼-- · 2020-02-02 04:56

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

查看更多
Ridiculous、
7楼-- · 2020-02-02 04:57

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)

查看更多
登录 后发表回答