在gradle上构建android应用程序

时间:2016-03-08 13:39:11

标签: android gradle admob dex

首先,我想承认我知道大多数关于gradle问题的问题。它不是重复的。问题类似于其他问题但所有解决方案都失败了当我添加了Google Play服务广告库时,问题就出现了。应用程序构建正常之前。添加经典问题后。

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' finished with non-zero exit value 1
in some cases exit value was 3

我已经多次使用多个模块排除项更改了gradle文件,扩大了android studio堆大小以及许多其他可能性。经过一切尝试,我无法弄清楚出了什么问题。

Gradle文件:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.google.gms.google-services'


repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://clojars.org/repo/" }
    maven { url "https://jitpack.io" }

}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "xxx"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    dexOptions {
        preDexLibraries = false
     //I have also tried enlarging heap size here
    }

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    lintOptions {
        checkReleaseBuilds false
    }
}

dependencies {
    compile 'com.android.support:multidex:1.0.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    apt "com.google.dagger:dagger-compiler:2.0.2"
    // Needed for @Generated annotation (missing in Java <= 1.6; therefore, Android)
    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }
    //ads lib ruined building
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile("com.google.android.gms:play-services-gcm:8.3.0") {
        exclude module: 'httpclient' //by artifact name
        exclude group: 'org.apache.httpcomponents' //by group
        exclude group: 'org.apache.httpcomponents', module: 'httpclient' //by both name and group
    }
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.google.guava:guava:19.0'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.squareup.okhttp:okhttp:2.7.4'
    compile('com.squareup.retrofit2:retrofit:2.0.0-beta4') {
        exclude module: 'okhttp'
    }
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
    compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
    compile 'com.google.code.gson:gson:2.5'
    compile 'com.google.dagger:dagger:2.0.2'
    compile('com.google.apis:google-api-services-youtube:v3-rev162-1.21.0') {
        exclude group: 'com.google.guava'
        exclude module: 'httpclient' //by artifact name
        exclude group: 'org.apache.httpcomponents' //by group
        exclude group: 'org.apache.httpcomponents', module: 'httpclient' //by both name and group
    }
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'io.reactivex:rxjava:1.1.0'
    compile 'com.github.orhanobut:logger:1.12'
    compile 'javax.annotation:jsr250-api:1.0'
    compile 'frankiesardo:icepick:3.1.0'
    apt 'frankiesardo:icepick-processor:3.1.0'
}

我不想使用整个Google Play服务lib。

发生错误时

Gradle 控制台输出

:app:transformClassesWithDexForDebug
Uncaught translation error: java.util.concurrent.ExecutionException:
java.lang.OutOfMemoryError: GC overhead limit exceeded Uncaught translation error:
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError:
GC overhead limit exceeded 2 errors; aborting FAILED

1 个答案:

答案 0 :(得分:0)

根据miva2cricket_007评论 - 他们是对的。图书馆太多了。我删除了

compile 'com.squareup.okhttp:okhttp:2.7.4'

从gradle构建文件和应用程序已构建。