yonutix
yonutix

Reputation: 2439

getApplicationContext() in AppCompatActivity (appcompatv7)

I have an android project with several packages, when I try to compile it I get

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/w3c/dom/Attr.class

I found on the internet a solution that implies adding the below rule, but when I add it

compile ('com.android.support:appcompat-v7:23.2.1'){
        exclude module: 'support-v4'
    }

I can not use getApplicationContext() method anymore.

My MainActivity looks like this:

public class MainActivity extends AppCompatActivity {

    public static Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //The below method is the one I can not use.
        context = getApplicationContext();
        ....
    }
}

Upvotes: 2

Views: 2411

Answers (1)

mojtaba
mojtaba

Reputation: 86

You must update your library support in the SDK manager.

Upvotes: 1

Related Questions