Gradle 不生成输出 APK

Gradle does not generate an output APK

我正在尝试在命令行上为我的 android 项目生成 APK。 我运行宁

./gradlew clean assembleProductionDebug

我得到的输出是:

:app:processProductionDebugManifest
:app:processProductionDebugResources
:app:generateProductionDebugSources
:app:compileProductionDebugJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:preDexProductionDebug
:app:dexProductionDebug
:app:processProductionDebugJavaRes UP-TO-DATE
:app:validateDebugSigning
:app:packageProductionDebug
:app:zipalignProductionDebug
:app:assembleProductionDebug

BUILD SUCCESSFUL

Total time: 2 mins 29.574 secs

但是,我的 build/outputs 文件夹是空的。当我 运行 时也会发生同样的情况 ./gradlew assemble

我可以搜索的唯一相关内容可能是 https://gradle.org/docs/current/dsl/org.gradle.language.assembler.tasks.Assemble.html,但如何在 build.gradle 中指定 objectFileDir?

注:运行宁

./gradlew clean installProductionDebug

在我的设备上成功安装了 APK。

相关build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'git-dependencies'
apply plugin: 'testfairy'
apply plugin: 'org.robolectric'


android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.test.androidas"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    signingConfigs {
        release {
             storeFile file("as.keystore")
             storePassword "***"
             keyAlias "as"
             keyPassword "***"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }


    productFlavors {
        production {
            applicationId "com.antsquare.test"
            versionCode 1
        }

        staging {
            applicationId "com.antsquare.test.staging"
            versionCode 1
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

    testfairyConfig {
        apiKey '***'
        video "wifi"
        notify true
        testersGroups "ME"
        autoUpdate true
        videoQuality "low"
        videoRate "0.5"
    }
}

先加

android { 

     compileSdkVersion 21
     buildToolsVersion "21.1.2"

     ...

     lintOptions { 
         abortOnError false 
     } 
}

app 模块中的 build.gradle。

之后通过 ./gradlew task clean 清理您的项目,然后从控制台调用 ./gradlew task build --debug | grep .apk 您将看到 apk 位置

在Android工作室中,

如果构建成功但没有生成

.apk

文件但未启动模拟器。

解决方案:确保在menubuild下方的下拉菜单或drop- 运行 的左侧被选择为 'app' 然后当你 运行 调试,

.apk

将生成文件并启动模拟器。