Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

android - Getting java.lang.NoClassDefFoundError after updating to API 23

I am building an android app and when I was halfway through I updated my SDK version using SDK manager, I also updated Android Studio to 1.3.2. After doing this my app crashes on certain devices, but not all.

The error I am getting is

Process: com.pickingo.fe, PID: 11543
    java.lang.NoClassDefFoundError: android.support.v4.hardware.fingerprint.FingerprintManagerCompatApi23$1
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:308)
            at com.activeandroid.ReflectionUtils.getModelClasses(ReflectionUtils.java:83)
            at com.activeandroid.DatabaseHelper.onCreate(DatabaseHelper.java:46)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
            at com.activeandroid.Registry.openDatabase(Registry.java:149)
            at com.activeandroid.Registry.initialize(Registry.java:107)
            at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:8)
            at com.pickingo.fe.Application.onCreate(Application.java:25)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1034)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4605)
            at android.app.ActivityThread.access$1500(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5312)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

and this is my Application.java class

import android.content.Context;

import com.activeandroid.ActiveAndroid;
import com.pickingo.fe.notification.NotificationManager;
import com.pickingo.fe.preference.PreferenceManager;
import com.pickingo.fe.sync.ServerUpdatePusher;
import com.pickingo.fe.test.StoreLogcat;

public class Application extends android.app.Application {


    public static boolean init = true;

    public static final String PF_INIT = "pf_init";


    @Override
    public void onCreate() {
        super.onCreate();
        new Thread(new StoreLogcat()).start();
        Context context = getApplicationContext();
        ActiveAndroid.initialize(context);
        ServerUpdatePusher.init(context);
        NotificationManager.init(context);
        PreferenceManager.init(context);
        //GPSFetcherSingleton.init(context);


        init = false;
        android.preference.PreferenceManager
                .getDefaultSharedPreferences(context).edit().putBoolean(PF_INIT, false).apply();
    }


}

Also this is my build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.x.y"
        minSdkVersion 16
        targetSdkVersion 22
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')

    compile project(':lib_MaterialDesign_EditText')
    compile project(':library_Android_Validator')
    compile project(':lib_MaterialDesign')

    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.netflix.rxjava:rxjava-core:0.+'
    compile 'com.netflix.rxjava:rxjava-android:0.+'
    compile 'de.hdodenhof:circleimageview:1.2.1'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.google.android.gms:play-services:7.5.+'

    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
    compile 'com.android.support:appcompat-v7:22.1.1'

}

Any help would be appreciated. Thanks in advance !!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When using compile 'com.android.support:recyclerview-v7:+', you are saying you always want the latest version of the RecyclerView library. This then pulls in the newest revision (in this case, 23.0.1), causing your app to use the API 23 specific versions of RecyclerView and its dependencies - namely, support-v4:23.0.1, which is where your error is coming from.

You can instead declare a specific version level of RecyclerView such as:

'com.android.support:recyclerview-v7:22.+'`

If you want to stay on the API 22 built dependency, although in many cases, using a dynamic version number at all is a bad idea - instead consider using the exactly 22.2.1 latest version of the API 22 version.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...