cannot resolve symbol 'Twitter' - Twitter Fabric

自作多情 提交于 2019-12-22 04:47:16

问题


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);
    }

}

回答1:


Try adding this to your gradle

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



回答2:


I also get same issue, And this is what worked for me.

After Sync Gradle file i just Rebuild my project (Android Studio File menu-> Build-> Rebuild Project). That's all.



来源:https://stackoverflow.com/questions/31248564/cannot-resolve-symbol-twitter-twitter-fabric

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!