Android Studio – Unable to open PNG file

android, android-studio, facebook

I'm trying to integrate Facebook into my app, but while running it in Android Studio, I get this:

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:
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

Unable to open PNG file… what?!

Code is totally the same as in "Getting Started with the Facebook SDK for Android (Android Studio)" guide. It's really simple, this is my

package com.example.aplikacebeta101;import android.os.Bundle;import;import android.content.Intent;import android.widget.TextView;import com.facebook.*;import com.facebook.model.*;public class MainActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        // start Facebook Login        Session.openActiveSession(this, true, new Session.StatusCallback() {            // callback when session changes state            @Override            public void call(Session session, SessionState state, Exception exception)             {            if (session.isOpened()) {                // make request to the /me API                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {                    // callback after Graph API response with user object                    @Override                    public void onCompleted(GraphUser user, Response response) {                        if (user != null) {                            TextView welcome = (TextView) findViewById(;                            welcome.setText("Hello " + user.getName() + "!");                        }                    }                });            }        }    });}@Overridepublic void onActivityResult(int requestCode, int resultCode, Intent data) {    super.onActivityResult(requestCode, resultCode, data);    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);}}

Any ideas? I know, Android Studio is still EAP, but I think this is not caused by Android Studio.

Best Solution

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. More info from MS:

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.)

Also see discussion why the limitation Windows exists.