天天看點

android studio(gradle)報錯ERROR: Unable to open PNG file原因

今天在編譯項目的時候碰到一個問題,代碼完全相同的情況下,隻是把項目移到SVN的另一個目錄,編譯無法通過

Gradle提示如下錯誤(不友善截自己的圖檔,網上轉一個):

Gradle: Execution failed for task ':AplikaceBeta1.0.1:mergeDebugResources'. Failed to run command: C:\Users\David\AppData\Local\Android\android-studio\sdk\build-tools\android-4.2.2\aapt.exe s -i C:\Users\David\Desktop\facebook-android-sdk-3.5\facebook-android-sdk-3.5\samples\AplikaceBeta1.0.1Project\AplikaceBeta1.0.1\build\exploded-bundles\AplikaceBeta101ProjectLibrariesFacebookUnspecified.aar\res\drawable\com_facebook_profile_picture_blank_square.png -o C:\Users\David\Desktop\facebook-android-sdk-3.5\facebook-android-sdk-3.5\samples\AplikaceBeta1.0.1Project\AplikaceBeta1.0.1\build\res\all\debug\drawable\com_facebook_profile_picture_blank_square.png Error Code: 42 Output: C:\Users\David\Desktop\facebook-android-sdk-3.5\facebook-android-sdk-3.5\samples\AplikaceBeta1.0.1Project\AplikaceBeta1.0.1\build\exploded-bundles\AplikaceBeta101ProjectLibrariesFacebookUnspecified.aar\res\drawable\com_facebook_profile_picture_blank_square.png ERROR: Unable to open PNG file

老外的答案還是很給力的:

Are you using Windows? This error could happen if the generated build file path exceeds the Windows (not NTFS) max path length of 260 characters. Make sure your project path is not too long, use short names as well.

Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)

總結原因,就是項目檔案路徑太長,超過了長度限制,256個字元

通過修改檔案名以及簡化路徑,減少相應檔案的深度,成功解決了這個問題。

希望小夥伴們能快速解決掉這個問題。

繼續閱讀