android 片段中的小吃店 - onClickListener() 构建 gradle 失败

snackbar in android fragment - onClickListener() build gradle fails

我试图在我的片段视图膨胀时显示小吃店。 我已经在 onViewCreated 中编写了 snackbar 代码,它可以工作并向我展示了 snackbar。但是当我尝试 setAction 并设置 onClickListener 时,Build gradle 失败了。我附上代码片段和错误日志。

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

错误日志

 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

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

你需要

  • 删除任何重复的示例

compile 'com.android.support:support-v4:23.1.0' compile "com.android.support:support-v4:+" 你已经添加了

  • 删除任何未使用的依赖项,例如 您需要此 com.google.android.gms:play-services:8.4.0 所有 google 播放服务吗?如果你只需要地图,你可以添加 com.google.android.gms:play-services-maps:8.4.0 not all service 检查 link for all google service https://developers.google.com/android/guides/setup

  • 尝试添加 defaultConfig { // Enabling multidex support. multiDexEnabled true } 检查 Link