-3

I am trying to show snackbar when my fragment view is inflated. I have written the snackbar code in onViewCreated, it works and shows me the snackbar. But when I am trying to setAction and set onClickListener the Build gradle fails. I am attaching the code snippet and error log.

FragmentContact.java

public void onViewCreated(View v, Bundle savedInstanceState) {

        Snackbar.make(getActivity().findViewById(android.R.id.content), "Doubt?", Snackbar.LENGTH_LONG)
                .setAction("Call",new View.OnClickListener(){

                    @Override
                    public void onClick(View v) {

                    }
                })
             .show();

Error Log

 FAILED

FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:dexDebug'.
    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0\bin\java.exe'' finished with non-zero exit value 2

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 44.306 secs

Dependencies in gradle

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile "com.android.support:support-v4:+"
    compile 'com.squareup.picasso:picasso:2.3.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Akshay Mahale
  • 63
  • 1
  • 7

1 Answers1

0

you need to

  • Remove any duplicated for example

compile 'com.android.support:support-v4:23.1.0' compile "com.android.support:support-v4:+" you already added

  • Remove any unused dependencies for example are you need this com.google.android.gms:play-services:8.4.0 all google play services. if you just need map you can add com.google.android.gms:play-services-maps:8.4.0 not all service check the link for all google service https://developers.google.com/android/guides/setup

  • Try to add defaultConfig { // Enabling multidex support. multiDexEnabled true } check the Link

Sally
  • 950
  • 9
  • 15
  • Clean your project then build. if not work try to add `defaultConfig { // Enabling multidex support. multiDexEnabled true } ` check the link (https://developer.android.com/tools/building/multidex.html#mdex-gradle) – Sally Feb 13 '16 at 19:39
  • Also check this post have the same issue (http://stackoverflow.com/questions/29028705/java-exe-finished-with-non-zero-exit-value-2-when-using-facebook-sdk) – Sally Feb 13 '16 at 19:42
  • Sally ! your workaround to add multiDexEnabled true worked for me! But is it recommended to go for it? since it has quiet a few drawbacks too! – Akshay Mahale Feb 14 '16 at 08:16
  • its clear that you have problem in dependencies. remove any duplicated, remove any unused dependencies, for example are you need this "com.google.android.gms:play-services:8.4.0" all google play services. if you just need map you can add " com.google.android.gms:play-services-maps:8.4.0" not all service check the link for all google service (https://developers.google.com/android/guides/setup) – Sally Feb 14 '16 at 09:36