Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot resolve symbol 'Twitter' - Twitter Fabric

I have an issue while trying to make use of Twitter login for my little Android app, It keeps giving error saying Cannot find symbol 'Twitter' I have searched online for several solutions including this one below but not found any possible solution.

Twitter Fabric - Cannot Resolve Symbol

I have Cleaned, rebuild, even restarted my Android studio, tried to Re-Sync Gradle but no solution yet.

This is my Build.Gradle (Project) Below

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
}

And this is my Build.Gradle (App)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }

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

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

    compile('com.twitter.sdk.android:twitter-core:1.3.1@aar') {
        transitive = true;
    }
}

And this is my Activity

public class TestActivity extends ActionBarActivity {

    String TWITTER_KEY="mykey";
    String TWITTER_SECRET="mysecret";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        /* Twitter */
        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        Fabric.with(this, new Twitter(authConfig));
        setUpTwitterButton();
    }


    TwitterLoginButton twitterButton;
    private void setUpTwitterButton() {

        twitterButton = (TwitterLoginButton) findViewById(R.id.login_button);
        twitterButton.setCallback(new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {

                Log.d("login:", "twitter:success");
                Log.d("Data", result.data.getUserName());

            }

            @Override
            public void failure(TwitterException exception) {
                Toast.makeText(getApplicationContext(),
                        "twitter Login failed",
                        Toast.LENGTH_SHORT).show();

            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // Pass the activity result to the login button.
        twitterButton.onActivityResult(requestCode, resultCode,
                data);
    }

}
like image 865
Tosin Onikute Avatar asked Jul 06 '15 14:07

Tosin Onikute


1 Answers

Try adding this to your gradle

compile('com.twitter.sdk.android:twitter:1.3.2@aar') {
        transitive = true;
    }
like image 187
rockfight Avatar answered Nov 15 '22 06:11

rockfight