为什么项目不能在Android Studio 1.5.1上编译?

时间:2016-01-25 12:28:09

标签: android android-gradle

以前,没有问题。我为OS X 10.11添加了一个全新的Android Studio 1.5.1并出现了这个错误:

Information:Gradle tasks [:app:assembleDebug]
:android_tools:preBuild UP-TO-DATE
:android_tools:preReleaseBuild UP-TO-DATE
:android_tools:compileReleaseNdk UP-TO-DATE
:android_tools:compileLint
:android_tools:copyReleaseLint UP-TO-DATE
:android_tools:checkReleaseManifest
:android_tools:preDebugAndroidTestBuild UP-TO-DATE
:android_tools:preDebugBuild UP-TO-DATE
:android_tools:preDebugUnitTestBuild UP-TO-DATE
:android_tools:preReleaseUnitTestBuild UP-TO-DATE
:android_tools:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:android_tools:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:android_tools:prepareReleaseDependencies
:android_tools:compileReleaseAidl UP-TO-DATE
:android_tools:compileReleaseRenderscript UP-TO-DATE
:android_tools:generateReleaseBuildConfig UP-TO-DATE
:android_tools:generateReleaseAssets UP-TO-DATE
:android_tools:mergeReleaseAssets UP-TO-DATE
:android_tools:generateReleaseResValues UP-TO-DATE
:android_tools:generateReleaseResources UP-TO-DATE
:android_tools:mergeReleaseResources UP-TO-DATE
:android_tools:processReleaseManifest UP-TO-DATE
:android_tools:processReleaseResources UP-TO-DATE
:android_tools:generateReleaseSources UP-TO-DATE
:android_tools:compileReleaseJavaWithJavac UP-TO-DATE
:android_tools:extractReleaseAnnotations UP-TO-DATE
:android_tools:mergeReleaseProguardFiles UP-TO-DATE
:android_tools:packageReleaseRenderscript UP-TO-DATE
:android_tools:packageReleaseResources UP-TO-DATE
:android_tools:processReleaseJavaRes UP-TO-DATE
:android_tools:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:android_tools:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
:android_tools:mergeReleaseJniLibFolders UP-TO-DATE
:android_tools:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
:android_tools:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
:android_tools:bundleRelease UP-TO-DATE
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:download_manager:preBuild UP-TO-DATE
:download_manager:preReleaseBuild UP-TO-DATE
:download_manager:compileReleaseNdk UP-TO-DATE
:download_manager:compileLint
:download_manager:copyReleaseLint UP-TO-DATE
:download_manager:checkReleaseManifest
:download_manager:preDebugAndroidTestBuild UP-TO-DATE
:download_manager:preDebugBuild UP-TO-DATE
:download_manager:preDebugUnitTestBuild UP-TO-DATE
:download_manager:preReleaseUnitTestBuild UP-TO-DATE
:download_manager:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:download_manager:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:download_manager:prepareReleaseDependencies
:download_manager:compileReleaseAidl UP-TO-DATE
:download_manager:compileReleaseRenderscript UP-TO-DATE
:download_manager:generateReleaseBuildConfig UP-TO-DATE
:download_manager:generateReleaseAssets UP-TO-DATE
:download_manager:mergeReleaseAssets UP-TO-DATE
:download_manager:generateReleaseResValues UP-TO-DATE
:download_manager:generateReleaseResources UP-TO-DATE
:download_manager:mergeReleaseResources UP-TO-DATE
:download_manager:processReleaseManifest UP-TO-DATE
:download_manager:processReleaseResources UP-TO-DATE
:download_manager:generateReleaseSources UP-TO-DATE
:download_manager:compileReleaseJavaWithJavac UP-TO-DATE
:download_manager:extractReleaseAnnotations UP-TO-DATE
:download_manager:mergeReleaseProguardFiles UP-TO-DATE
:download_manager:packageReleaseRenderscript UP-TO-DATE
:download_manager:packageReleaseResources UP-TO-DATE
:download_manager:processReleaseJavaRes UP-TO-DATE
:download_manager:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:download_manager:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
:download_manager:mergeReleaseJniLibFolders UP-TO-DATE
:download_manager:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
:download_manager:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
:download_manager:bundleRelease UP-TO-DATE
:media_webbrowser:preBuild UP-TO-DATE
:media_webbrowser:preReleaseBuild UP-TO-DATE
:media_webbrowser:compileReleaseNdk UP-TO-DATE
:media_webbrowser:compileLint
:media_webbrowser:copyReleaseLint UP-TO-DATE
:media_webbrowser:mergeReleaseProguardFiles UP-TO-DATE
:media_webbrowser:packageReleaseRenderscript UP-TO-DATE
:media_webbrowser:checkReleaseManifest
:media_webbrowser:prepareReleaseDependencies
:media_webbrowser:compileReleaseRenderscript UP-TO-DATE
:media_webbrowser:generateReleaseResValues UP-TO-DATE
:media_webbrowser:generateReleaseResources UP-TO-DATE
:media_webbrowser:packageReleaseResources UP-TO-DATE
:media_webbrowser:compileReleaseAidl UP-TO-DATE
:media_webbrowser:generateReleaseBuildConfig UP-TO-DATE
:media_webbrowser:generateReleaseAssets UP-TO-DATE
:media_webbrowser:mergeReleaseAssets UP-TO-DATE
:media_webbrowser:processReleaseManifest UP-TO-DATE
:media_webbrowser:processReleaseResources UP-TO-DATE
:media_webbrowser:generateReleaseSources UP-TO-DATE
:media_webbrowser:compileReleaseJavaWithJavac UP-TO-DATE
:media_webbrowser:processReleaseJavaRes UP-TO-DATE
:media_webbrowser:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:media_webbrowser:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
:media_webbrowser:mergeReleaseJniLibFolders UP-TO-DATE
:media_webbrowser:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
:media_webbrowser:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
:media_webbrowser:bundleRelease UP-TO-DATE
:app:prepareAndroidavdownloaderAndroid_toolsUnspecifiedLibrary UP-TO-DATE
:app:prepareAndroidavdownloaderDownload_managerUnspecifiedLibrary UP-TO-DATE
:app:prepareAndroidavdownloaderMedia_webbrowserUnspecifiedLibrary UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAds840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement840Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:transformClassesWithDexForDebug
Uncaught translation error: com.android.dex.util.ExceptionWithContext
1 error; aborting
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 '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 36.102 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

app build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        applicationId 'com.xxx.xxx'
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 23
        versionName '2.5'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }

    dexOptions {
        incremental = true;
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':download_manager')
    compile project(':media_webbrowser')
    compile project(':android_tools')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
}

android_tools build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
}

download_manager build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
}

media_webbrowser build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

许多人试图解决这个问题。什么都没有帮助。告诉我什么可能是错的?

=============

我找到了一个出现错误的地方(在模块media_webbrowser中)。 此时传递给新对象接口的方法时出现错误:http://pastebin.com/jpUBznZ5

传递null时,没有错误:http://pastebin.com/Ewi7jz0q

============

通过安装jdk8而不是jdk7

解决了问题

3 个答案:

答案 0 :(得分:3)

从构建gradle文件中删除compile 'com.google.android.gms:play-services:8.4.0',然后重试

因为您必须使用完整的Google Play服务库或Google Play服务的各个部分。使用其中一个。

下面的

使用完整的Google Play服务库

compile 'com.google.android.gms:play-services:8.4.0'

因此,如果您使用Google Play服务的单独部分(例如com.google.android.gms:play-services-ads:8.4.0),则无需添加。

这就是为什么你的应用dex尺寸增加Over 65K Methods

来自documentation

有选择地将API编译为可执行文件

  

在6.5之前的Google Play服务版本中,您必须进行编译   整个API包进入您的应用程序。在某些情况下,这样做了   保持应用程序中的方法数量更加困难(包括   65,536下的框架API,库方法和您自己的代码   限制。

     

从版本6.5开始,您可以选择性地编译Google Play   将API服务到您的应用中。例如,仅包含Google   Fit和Android Wear API,替换您的以下行   build.gradle文件:

     

compile' com.google.android.gms:play-services:8.4.0'用这些线:

     

编译com.google.android.gms:play-services-fitness:8.4.0'编   ' com.google.android.gms:玩服务耐磨:8.4.0'

答案 1 :(得分:0)

也许您已经看到了issue

我将在此处复制该帖子中的解决方案,以防万一以后链接中断。

如果您使用" - info --debug"进行编译并注意到内存不足错误,将此块添加到gradle.build应该解决它。

android {
    dexOptions {
        incremental = true;
        preDexLibraries = false
        javaMaxHeapSize "4g" // 2g should be also OK
    }
}

答案 2 :(得分:0)

通过安装jdk8而不是jdk7

解决了问题