构建期间Android Studio Gradle失败

时间:2017-07-12 18:23:00

标签: android android-gradle

以下是我的问题场景:

我无法在android studio中构建和运行我的应用程序。在安装apk之前似乎失败了以下错误。但是,当我使用gradle包装器通过命令行构建应用程序时,事情进展顺利。显然这并不理想,因为其他团队成员需要使用该项目,而android studio的IDE UI应该足够了。

当我在Android Studio中构建并运行我的应用时,我在构建步骤中遇到错误:

transformClassesAndResourcesWithProguardForRelease FAILED 

path may not be null or empty: path='null'

但是当我调用命令时:

./gradlew cleanRelease assembleRelease installRelease,

这将在设备上构建并安装工作版本。

我也可以构建 - >生成签名Apk,这样可行。

所以按下Android工作室上的运行按钮(>)是唯一不起作用的东西......奇怪的是,当我只指定一个abi时,它有效,但当我把所有三个abi都不起作用时

我的问题是:

为什么会显示此消息?什么路径是null?以及如何解决这个问题。

apply plugin: 'com.android.application'

////Grab location of opencv sdk
String systemHome = System.getenv('HOME');
File libDir = new File(systemHome + "/Library/Android/sdk/OpenCV-android-sdk");

//If home directory exists choose this path, otherwise we're doing CI 
//with jenkins so we can hardcode this ...
String opencvSdkPath =
    (libDir != null && libDir.isDirectory()) ?
            systemHome + "/Library/Android/sdk/OpenCV-android-sdk/sdk/native/libs"
            :
            "/Users/userx/Library/Android/OpenCV-android-sdk/sdk/native/libs";

println("Look for opencv within " + opencvSdkPath)

android {
signingConfigs {
    XSigningCredentials {
        keyAlias 'asdfsdf'
        keyPassword 'asdfasdf'
        storeFile file('asdfsdf.jks')
        storePassword 'asdfsdf'
    }
}
compileSdkVersion 25
buildToolsVersion '25.0.2'
//Give the default configurations for gradles build
defaultConfig {
    //Package name
    applicationId "a.b.c"

    //Minimum working sdk
    minSdkVersion 19

    //Target sdk with support
    targetSdkVersion 25

    //Actual version ID
    versionCode vrsCode as Integer

    //Google play visible version string
    versionName vrsCustomerFacingCode

    multiDexEnabled true

    ndk {
        abiFilters 'armeabi', 'armeabi-v7a', 'x86'
    }
    externalNativeBuild {
        cmake {
            cppFlags "-std=c++11" ,
                    "-latomic",
                    "-DASSIMP_BUILD_NO_X_IMPORTER",
                    "-DASSIMP_BUILD_NO_3DS_IMPORTER",
                    "-DASSIMP_BUILD_NO_MD3_IMPORTER",
                    "-DASSIMP_BUILD_NO_MDL_IMPORTER",
                    "-DASSIMP_BUILD_NO_MD2_IMPORTER",
                    "-DASSIMP_BUILD_NO_PLY_IMPORTER",
                    "-DASSIMP_BUILD_NO_ASE_IMPORTER",
                    "-DASSIMP_BUILD_NO_HMP_IMPORTER",
                    "-DASSIMP_BUILD_NO_SMD_IMPORTER",
                    "-DASSIMP_BUILD_NO_MDC_IMPORTER",
                    "-DASSIMP_BUILD_NO_MD5_IMPORTER",
                    "-DASSIMP_BUILD_NO_STL_IMPORTER",
                    "-DASSIMP_BUILD_NO_LWO_IMPORTER",
                    "-DASSIMP_BUILD_NO_DXF_IMPORTER",
                    "-DASSIMP_BUILD_NO_NFF_IMPORTER",
                    "-DASSIMP_BUILD_NO_RAW_IMPORTER",
                    "-DASSIMP_BUILD_NO_OFF_IMPORTER",
                    "-DASSIMP_BUILD_NO_AC_IMPORTER",
                    "-DASSIMP_BUILD_NO_BVH_IMPORTER",
                    "-DASSIMP_BUILD_NO_IRRMESH_IMPORTER",
                    "-DASSIMP_BUILD_NO_IRR_IMPORTER",
                    "-DASSIMP_BUILD_NO_Q3D_IMPORTER",
                    "-DASSIMP_BUILD_NO_B3D_IMPORTER",
                    "-DASSIMP_BUILD_NO_COLLADA_IMPORTER",
                    "-DASSIMP_BUILD_NO_TERRAGEN_IMPORTER",
                    "-DASSIMP_BUILD_NO_CSM_IMPORTER",
                    "-DASSIMP_BUILD_NO_3D_IMPORTER",
                    "-DASSIMP_BUILD_NO_LWS_IMPORTER",
                    "-DASSIMP_BUILD_NO_OGRE_IMPORTER",
                    "-DASSIMP_BUILD_NO_MS3D_IMPORTER",
                    "-DASSIMP_BUILD_NO_COB_IMPORTER",
                    "-DASSIMP_BUILD_NO_Q3BSP_IMPORTER",
                    "-DASSIMP_BUILD_NO_NDO_IMPORTER",
                    "-DASSIMP_BUILD_NO_IFC_IMPORTER",
                    "-DASSIMP_BUILD_NO_XGL_IMPORTER",
                    "-DASSIMP_BUILD_NO_FBX_IMPORTER",
                    "-DASSIMP_BUILD_NO_C4D_IMPORTER",
                    "-DASSIMP_BUILD_NO_OPENGEX_IMPORTER",
                    "-DASSIMP_BUILD_NO_ASSBIN_IMPORTER",
                    "-DASSIMP_BUILD_NO_BLEND_IMPORTER",
                    "-DASSIMP_BUILD_NO_GEO_IMPORTER",
                    "-DANDROID -fPIC",
                    "-DANDROID -fsigned-char",
                    "-mstackrealign",
                    "-O2",
                    "-fexceptions",
                    "-frtti"

            cFlags "-latomic",
                    "-DASSIMP_BUILD_NO_X_IMPORTER",
                    "-DASSIMP_BUILD_NO_3DS_IMPORTER",
                    "-DASSIMP_BUILD_NO_MD3_IMPORTER",
                    "-DASSIMP_BUILD_NO_MDL_IMPORTER",
                    "-DASSIMP_BUILD_NO_MD2_IMPORTER",
                    "-DASSIMP_BUILD_NO_PLY_IMPORTER",
                    "-DASSIMP_BUILD_NO_ASE_IMPORTER",
                    "-DASSIMP_BUILD_NO_HMP_IMPORTER",
                    "-DASSIMP_BUILD_NO_SMD_IMPORTER",
                    "-DASSIMP_BUILD_NO_MDC_IMPORTER",
                    "-DASSIMP_BUILD_NO_MD5_IMPORTER",
                    "-DASSIMP_BUILD_NO_STL_IMPORTER",
                    "-DASSIMP_BUILD_NO_LWO_IMPORTER",
                    "-DASSIMP_BUILD_NO_DXF_IMPORTER",
                    "-DASSIMP_BUILD_NO_NFF_IMPORTER",
                    "-DASSIMP_BUILD_NO_RAW_IMPORTER",
                    "-DASSIMP_BUILD_NO_OFF_IMPORTER",
                    "-DASSIMP_BUILD_NO_AC_IMPORTER",
                    "-DASSIMP_BUILD_NO_BVH_IMPORTER",
                    "-DASSIMP_BUILD_NO_IRRMESH_IMPORTER",
                    "-DASSIMP_BUILD_NO_IRR_IMPORTER",
                    "-DASSIMP_BUILD_NO_Q3D_IMPORTER",
                    "-DASSIMP_BUILD_NO_B3D_IMPORTER",
                    "-DASSIMP_BUILD_NO_COLLADA_IMPORTER",
                    "-DASSIMP_BUILD_NO_TERRAGEN_IMPORTER",
                    "-DASSIMP_BUILD_NO_CSM_IMPORTER",
                    "-DASSIMP_BUILD_NO_3D_IMPORTER",
                    "-DASSIMP_BUILD_NO_LWS_IMPORTER",
                    "-DASSIMP_BUILD_NO_OGRE_IMPORTER",
                    "-DASSIMP_BUILD_NO_MS3D_IMPORTER",
                    "-DASSIMP_BUILD_NO_COB_IMPORTER",
                    "-DASSIMP_BUILD_NO_Q3BSP_IMPORTER",
                    "-DASSIMP_BUILD_NO_NDO_IMPORTER",
                    "-DASSIMP_BUILD_NO_IFC_IMPORTER",
                    "-DASSIMP_BUILD_NO_XGL_IMPORTER",
                    "-DASSIMP_BUILD_NO_FBX_IMPORTER",
                    "-DASSIMP_BUILD_NO_C4D_IMPORTER",
                    "-DASSIMP_BUILD_NO_OPENGEX_IMPORTER",
                    "-DASSIMP_BUILD_NO_ASSBIN_IMPORTER",
                    "-DASSIMP_BUILD_NO_BLEND_IMPORTER",
                    "-DASSIMP_BUILD_NO_GEO_IMPORTER",
                    "-DANDROID -fPIC",
                    "-DANDROID -fsigned-char",
                    "-mstackrealign",
                    "-O2",
                    "-fexceptions",
                    "-frtti"

            arguments "-DANDROID_STL=gnustl_shared"

        }
    }
}
splits {

    // Configures screen ABI split settings

    abi {

        // Enable ABI APK splits
        enable true

        // Resets the list of ABIs that Gradle should create APKs for to none
        reset()

        // Specifies a list of ABIs that Gradle should create APKs for
        include "armeabi", "armeabi-v7a", "x86"

        // Specify that we do not want to also generate a universal APK that includes all ABIs
        universalApk false
    }

}
buildTypes {
    release {
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.XSigningCredentials
        minifyEnabled true
    }
    debug {
        debuggable true
        minifyEnabled false
    }
}
packagingOptions {
    exclude 'META-INF/services/javax.annotation.processing.Processor'
    pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
    pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
    pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
    pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
}
dexOptions {
    javaMaxHeapSize "2g"
}
externalNativeBuild {
    cmake {
        path 'CMakeLists.txt'
    }
}
sourceSets {
    main {
        jniLibs.srcDirs opencvSdkPath, 'src/main/jni/ffmpeg'
    }
    }
}
// map for the version code that gives each ABI a value
ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'x86': 3]

// For each APK output variant, override versionCode with an ABI value 
schema
android.applicationVariants.all { variant ->
    // assign different version code for each output
    variant.outputs.each { output ->
        output.versionCodeOverride =((project.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI)) * 1000000)
                    + android.defaultConfig.versionCode)
}
}

repositories {
    mavenCentral()
}

configurations {
all*.exclude group: 'org.bytedeco', module: 'javacpp-presets'
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':openCVLibrary310')
compile 'org.bytedeco.javacpp-presets:opencv:3.1.0-1.2'
compile 'org.bytedeco.javacpp-presets:ffmpeg:3.0.2-1.2'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'org.bytedeco.javacpp-presets:opencv:3.1.0-1.2'
compile 'org.bytedeco.javacpp-presets:ffmpeg:3.0.2-1.2'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'org.bytedeco:javacv:1.2'
compile 'org.bytedeco:javacpp:1.2.4'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-core:11.0.2'
compile 'com.google.firebase:firebase-crash:11.0.2'
compile 'com.google.firebase:firebase-auth:11.0.2'
compile 'com.google.android.gms:play-services-auth:11.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'com.desk:sdk:1.3.1'
compile 'se.akerfeldt:okhttp-signpost:1.1.0'
compile 'oauth.signpost:signpost-core:1.2.1.2'
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'com.github.tony19:logback-android-core:1.1.1-6'
compile 'com.github.tony19:logback-android-classic:1.1.1-6'
testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

2 个答案:

答案 0 :(得分:2)

要调试其中一个Gradle任务在按下“运行”按钮时失败,您可以在Android Studio中启用命令行选项 - >设置 - >构建,执行,部署 - >编译器。将命令行选项设置为--stacktrace --debug。按Run按钮并检查Gradle Console窗口中的输出。

可能你在三个ABI之间存在一些依赖关系,这些ABI会被重置并影响其他ABI,但如果没有更多日志,很难知道。

答案 1 :(得分:0)

我没有评论的声誉。 我想知道您是否使用Instant Run?在尝试构建版本apk时,请不要启用即时运行

点击此处查看有关Android studio - Instant run & Proguard

的更多信息