android - Gradle 不生成输出 APK

标签 android gradle gradlew

我正在尝试在命令行上为我的 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

但是,我的构建/输出文件夹是空的。我运行时也会发生同样的情况 ./gradlew 组装

我唯一可以搜索的相关内容可能是 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 - Gradle 不生成输出 APK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28994942/

相关文章:

java - gradle可以自动创建META-INF、WEB-INF文件夹和web.xml吗?

android - 按钮无法解析为类型

android - 在浏览器中打开 url 并强制重新加载页面

java - 是否可以在 while 循环中设置可变数量的条件?

java - spring boot Hibernate报错java.lang.NoSuchMethodError : javax. persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;

tomcat - 多个 Spring 引导配置

gradle - 使用 gradlew 和 gradle 的区别

android - 在没有 Gradle 的情况下为您的应用程序配置 Multidex

android - 在代理后面工作的 Flutter android studio 3.2 中的 Gradle 问题

android - € 登录方法名称使用 Gradle 测试用例失败