0

I am currently starting to develop a new Android application using Android Studio. I have updated the Gradle build file and I have successfully added the Crouton Library. I have a Drawer Navigation setup and when I click on an item I want to test the Crouton by displaying it so I used the code below:

@Override
public void onNavigationDrawerItemSelected(int position) {
     Crouton.makeText(this, "Test", Style.ALERT).show();
}

When I run this code it builds fine but the app crashes and I get the stack trace below:

11-07 19:49:10.474    1212-1212/com.oss.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: de.keyboardsurfer.android.widget.crouton.Style
            at com.oss.app.HomeActivity.onNavigationDrawerItemSelected(HomeActivity.java:59)
            at com.oss.app.NavigationDrawerFragment.selectItem(NavigationDrawerFragment.java:204)
            at com.oss.app.NavigationDrawerFragment.onCreate(NavigationDrawerFragment.java:79)
            at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:893)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
            at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184)
            at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
            at android.app.Activity.setContentView(Activity.java:1867)
            at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
            at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:111)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
            at com.oss.app.HomeActivity.onCreate(HomeActivity.java:40)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

I understand that the issue is to do with the Style class not being found at run-time but I have added it as an import on the page so I don't know what could be causing this. I would really appreciate some help on this.

Thanks in advance


Edit


My build.gradle file is below:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 18
    }
}

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/com.haarman.listviewanimations-2.5.2.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile 'com.android.support:appcompat-v7:+'
    compile ('de.keyboardsurfer.android.widget:crouton:1.8.1') {
        exclude module: 'support-v4'
        compile 'com.android.support:support-v4:18.0.+'
    }
}
4

1 回答 1

1

通过 Gradle 在 Android Studio 中添加库时,我经常遇到同样的问题。对我有用的是从项目文件夹内的控制台运行“gradlew.bat clean assembleDebug”。

于 2013-11-07T20:21:43.553 回答