Gradle未生成输出APK文件。

6
我正在尝试通过命令行为我的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"
    }
}

是的,如果没有,请清理您的项目并运行“./gradlew build”。 - Konrad Krakowiak
请使用一些文件浏览器而不是Android Studio。 - Konrad Krakowiak
是的,我正在使用 ls -A build/outputs/apk 命令。但是它是空的。 - recipherus
首先通过 ./gradlew task clean 清理你的项目,然后在控制台中调用 ./gradlew task build --debug | grep .apk 命令,你将看到 apk 文件的位置。 - Konrad Krakowiak
./gradlew task build 给我返回了一个 lint 错误: android { lintOptions { abortOnError false } } - recipherus
显示剩余6条评论
2个回答

3
首先添加:

android { 

     compileSdkVersion 21
     buildToolsVersion "21.1.2"

     ...

     lintOptions { 
         abortOnError false 
     } 
}

app模块的build.gradle中进行以下配置。

之后通过./gradlew task clean命令清理项目,然后从控制台调用./gradlew task build --debug | grep .apk命令,你就会看到apk文件所在位置。


尝试执行以下命令:cd /Users/jimwang/dev/test/AndroidAS/app/build/outputs/apk - Konrad Krakowiak
ls -a之后 - Konrad Krakowiak
在你的Android Studio控制台中。 - Konrad Krakowiak
必须有这些文件。 - Konrad Krakowiak
是的,你说得对,那时我实际上在看错文件夹了。谢谢! - recipherus
显示剩余2条评论

2
在 Android Studio 中,如果构建成功但没有生成.apk文件并且不启动模拟器。
解决方案:确保在菜单下的“构建”下拉菜单或左侧的“运行”下拉菜单中选择了“app”,然后当您运行或调试时,.apk文件将被生成并且模拟器将启动。

请确保在运行或调试时,下拉菜单中的构建菜单或左侧的下拉菜单已选择为“应用程序”,否则我找不到任何类似的内容。 - PRMan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接