Cause: buildOutput.apkData must not be null

2020-02-02 05:04发布

问题:

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

回答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'


回答2:

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.



回答3:

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.



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



回答5:

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



回答6:

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.



回答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



回答8:

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



回答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



回答10:

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.



回答11:

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


回答12:

Just change the Apk release/debug location.

EX:

/home/sanaebadi/Desktop

after change :

/home/sanaebadi/apk


回答13:

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



回答14:

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.



回答15:

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



回答16:

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)



回答17:

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.



回答18:

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



回答19:

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



回答20:

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.



回答21:

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

2- Delete the build folder

3- clean project



回答22:

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



回答23:

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



回答24:

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



回答25:

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


回答26:

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 current destination path is

c:\user\folder\project\app

change it to

c:\user\folder\project

then it will generate the signed apk successfully.



回答27:

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

File->sync project with gradle files.