Error: Program type already present Android Studio

1

I'm trying to use the Twitter API to only show a tweet, the application does not have any code but it gives me the following error:

  

Program type already present: android.support.v4.app.FragmentTransitionCompat21 $ 1   Message {kind = ERROR, text = Program type already present: android.support.v4.app.FragmentTransitionCompat21 $ 1, sources = [Unknown source file], tool name = Optional.of (D8)}

I have been reading online that the problem is that I have something duplicated in the build.grandle but I have reviewed and I do not see anything strange, this is my code:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.models.Tweet;
import com.twitter.sdk.android.tweetui.TweetUtils;
import com.twitter.sdk.android.tweetui.TweetView;

public class MainActivity extends AppCompatActivity {

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

    final LinearLayout myLayout
            = (LinearLayout) findViewById(R.id.layTwitter);

    final long tweetId = 510908133917487104L;
    TweetUtils.loadTweet(tweetId, new Callback<Tweet>() {
        @Override
        public void success(Result<Tweet> result) {
            myLayout.addView(new TweetView(MainActivity.this, result.data));
        }

        @Override
        public void failure(TwitterException exception) {
            // Toast.makeText(...).show();
        }
    });

}
}

And this is the code of build.gradle :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.cpadilla.embedtweet"
        minSdkVersion 20
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner        "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),     'proguard-rules.pro'
    }
    }
}

dependencies {
implementation 'com.twitter.sdk.android:twitter:3.1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

The only line that I added is that of

  

implementation 'com.twitter.sdk.android:twitter:3.1.1'

Thank you very much in advance, does anyone know how to fix this problem?

Greetings!

    
asked by cpadilla 26.04.2018 в 13:08
source

1 answer

1

I have already found a solution, I do not know if it will be good but it works, I have stated it in the following way:

compile ('com.twitter.sdk.android:twitter:3.1.1'){
    exclude module: 'support-v4'
}

And with this it works perfectly

    
answered by 26.04.2018 в 15:44