当Google Play服务添加为依赖项时,无法使用gradle构建

时间:2014-08-12 08:59:44

标签: android google-maps gradle android-studio google-play-services

我正在尝试将Google Play服务添加到我的项目中以使用MapView,但是当我将其添加到build.gradle compile "com.google.android.gms:play-services:5.2.08"时,我遇到了构建错误

:app:mergeDebugResources
D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-mdpi\common_signin_btn_text_disabled_focus_light.9.png ERROR: Unable to open PNG file
D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-hdpi\common_signin_btn_icon_focus_light.9.png ERROR: Unable to open PNG file
D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-xhdpi\common_signin_btn_icon_normal_light.9.png ERROR: Unable to open PNG file
D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-mdpi\ic_plusone_medium_off_client.png ERROR: Unable to open PNG file
D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-xhdpi\common_signin_btn_text_normal_dark.9.png ERROR: Unable to open PNG file
D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-xhdpi\common_signin_btn_text_pressed_dark.9.png ERROR: Unable to open PNG file
Error:Failed to run command:
    C:\...\AndroidStudio\sdk\build-tools\android-4.4W\aapt.exe s -i D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-mdpi\common_signin_btn_text_disabled_focus_light.9.png -o D:\...\app\build\intermediates\res\debug\drawable-mdpi-v4\common_signin_btn_text_disabled_focus_light.9.png
Error Code:
    42
Output:
    D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-mdpi\common_signin_btn_text_disabled_focus_light.9.png ERROR: Unable to open PNG file
:app:mergeDebugResources FAILED
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: Failed to run command:
    C:\...\AndroidStudio\sdk\build-tools\android-4.4W\aapt.exe s -i D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-mdpi\common_signin_btn_text_disabled_focus_light.9.png -o D:\...\app\build\intermediates\res\debug\drawable-mdpi-v4\common_signin_btn_text_disabled_focus_light.9.png
Error Code:
    42
Output:
    D:\...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\5.2.08\res\drawable-mdpi\common_signin_btn_text_disabled_focus_light.9.png ERROR: Unable to open PNG file

我的build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-L'
    buildToolsVersion "20.0.0"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    defaultConfig {
        applicationId "com.test.myapp"
        minSdkVersion 'L'
        targetSdkVersion 'L'
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    compile 'com.android.support:support-v4:21.0.0-rc1'
    compile 'com.android.support:palette-v7:21.0.0-rc1'
    compile 'com.android.support:cardview-v7:21.0.0-rc1'
    compile 'com.android.support:support-v13:21.0.0-rc1'

    compile "com.google.android.gms:play-services:5.2.08"
}

我在SDK Manager上安装了Extras,Android L,Android 4.4W和Android 4.4.2(一切都是最新的)

尝试添加compile 'com.android.support:appcompat-v7:21.0.0-rc1',重建项目仍然无效

2 个答案:

答案 0 :(得分:10)

感谢this post!导致问题的文件路径超过260个字符,无法在NTFS文件系统上工作(对不起,我忘了提到我使用的是Windows 7)

您可以选择此工具http://www.ntwind.com/software/utilities/visual-subst.html来缩短路径并克服mergeDebugResource异常

答案 1 :(得分:0)

我也打了这个,答案和你记录的一样(谢谢!) - 构建失败引用一个很长的路径名。我试图在以下地方建立样本:

https://github.com/playgameservices/android-basic-samples

我将toplevel文件夹移动到更短路径的root。然后构建完全干净。

是的,它是在运行NTFS文件系统的Win7盒子上。

让我想起古老的说法 - 计算机科学中只有三个好的数字:

0, 1, and infinity

干杯,

相关问题