android – 无法解析符号’Twitter’ – Twitter Fabric

前端之家收集整理的这篇文章主要介绍了android – 无法解析符号’Twitter’ – Twitter Fabric前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图利用Twitter登录我的小 Android应用程序时遇到问题,它一直给出错误说无法找到符号’Twitter’我在网上搜索了几个解决方案,包括下面的这个,但没有找到任何可能的解决方案.

Twitter Fabric – Cannot Resolve Symbol

我已经清理,重建,甚至重新启动我的Android工作室,尝试重新同步Gradle但尚无解决方案.

这是我的Build.Gradle(Project)

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' }
    }
}

这是我的Build.Gradle(应用程序)

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

这是我的活动

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

}

解决方法

尝试将此添加到您的gradle
compile('com.twitter.sdk.android:twitter:1.3.2@aar') {
        transitive = true;
    }

猜你在找的Android相关文章