0

I get 'Specify location of the gradle or android eclipse project'. I followed the following steps:

1) Added mavenCentral and dependency in app->build.gradle as

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.akshitag.cooltrends"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}


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

2) Build the project which is successful.

3) Download and Unzip facebook sdk. Use Import Module under File->New and select facebook folder. Inside the unzipeed older, I have this: \facebook-android-sdk-4.9.0\facebook-android-sdk-4.9.0. It contains AudienceNetwork and facebook folder. Inside facebook folder, I have following files: sample, facebook-android-sdk-4.9.0.aar, licence.txt and notice.txt

I get the following error

Also, this is how my project structure looks like. enter image description here

Could anyone guide me here please?

Atihska
  • 4,803
  • 10
  • 56
  • 98
  • https://github.com/ParsePlatform/ParseUI-Android check dependencies to fb inclusion of 4.6 in this project. – Robert Rowntree Jan 19 '16 at 07:11
  • @RobertRowntree Thanks for replying. I added this one compile 'com.parse:parsefacebookutils-v4-android:1.10.3@aar' and still I couldn't import module. And this seems library for parseUI. – Atihska Jan 20 '16 at 05:20

2 Answers2

0

You already compiled sdk in gradle then why you want to add it again using different method ? Your project is done, you don't need to add it as a separate module.

Rajbir Shienh
  • 2,965
  • 1
  • 14
  • 21
0

you do not need to import facebook SDK files in android studio just go to your app module gradle: build.gradle and paste

 repositories {

    mavenCentral()
}
dependencies {
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.facebook.android:facebook-android-sdk:4.8.0'
}

.Do not forget to sync . at this time min sdk version must me 15 and go to https://developers.facebook.com/ then create your app id and paste it in values >> trings.xml also do not forget to create your app keyHASH .

in your project create the following file:MyApplication.java

paste in these codes:

public class MyApplication extends Application {
    // Updated your class body:
   @Override
    public void onCreate() {
    super.onCreate();
    // Initialize the SDK before executing any other operations,
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);
}

}

Make your make your SigninFragment like this :

      public class SigninFragment extends Fragment {

    CallbackManager callbackManager;
    private LoginButton loginButton;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Other app specific specialization
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(getActivity());
        callbackManager = CallbackManager.Factory.create();
        // Initialize the SDK before executing any other operations,
        View rootView = inflater.inflate(R.layout.signin_fragment, container, false);




        loginButton = (LoginButton)rootView.findViewById(R.id.login_button);
        loginButton.setReadPermissions("email");
        // If using in a fragment
        loginButton.setFragment(this);




        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Toast.makeText(getApplicationContext(), "Login attempt succes.",Toast.LENGTH_LONG).show();

            }

            @Override
            public void onCancel() {
              Toast.makeText(getApplicationContext(), "Login attempt cancelled.",Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(FacebookException e) {
                Toast.makeText(getApplicationContext(), "Login attempt failed.",Toast.LENGTH_LONG).show();
            }
        });



        return rootView;
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }

How your android manifest must look like:

  //facebook
    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:label="@string/app_name"
        android:exported="true"
        >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>
    <meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>



    //end facebook

What must be found in strings.xml :

    <string name="facebook_app_id">here there is id number you get from facebook developpers</string>
    <string name="fb_login_protocol_scheme">fbAPP_ID</string>

I your signinFragment.xml add facebook button like this :

  <com.facebook.login.widget.LoginButton
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="71dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />