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条回答
Animai°情兽
2楼-- · 2020-02-02 04:47

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'
查看更多
倾城 Initia
3楼-- · 2020-02-02 04:48

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

File->sync project with gradle files.

查看更多
Anthone
4楼-- · 2020-02-02 04:49

Just change the Apk release/debug location.

EX:

/home/sanaebadi/Desktop

after change :

/home/sanaebadi/apk
查看更多
干净又极端
5楼-- · 2020-02-02 04:51

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

查看更多
Root(大扎)
6楼-- · 2020-02-02 04:51

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.

查看更多
Anthone
7楼-- · 2020-02-02 04:52

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

查看更多
登录 后发表回答