运行时期间未找到类异常

时间:2016-04-17 18:08:46

标签: java android runtime-error classnotfoundexception android-facebook

我正在开发一个Android应用程序,并遇到了java.lang.ClassNotFoundException。几个小时前,我很高兴地构建我的应用程序,当我尝试编译它时,它在运行时期间因上述错误而崩溃,但完全编译。

我很困惑这可能是问题的原因,因为这不是将类添加到清单的简单修复,因为我已经这样做了。

还没有找到facebook SDK,这非常令人担心,因为我已导入它并且在编译之前没有显示任何错误。

在几分钟前运行我的应用程序时,当我尝试提出解决方案时,我的活动在相同的异常情况下崩溃,即使它们都已在清单中声明并且一切设置正确。我不知道是否会发生这种情况,因为我在活动中使用了碎片或其他东西。基本上,在我将Facebook添加到应用程序之前,它工作得非常好。现在肯定比我现在的状态好,这是肯定的。

这是我的Android清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.powerofpixels.magpie" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name=".Magpie">

        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

        <!-- Facebook activity for login and sharing -->
        <activity android:name="com.facebook.FacebookActivity"
                  android:configChanges=
                  "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar"
                  android:label="@string/app_name" />

        <activity android:name=".ui.activity.BirthdayFeedActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".ui.activity.AuthActivity" ></activity>

    </application>

</manifest>

以下是gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.powerofpixels.magpie"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.facebook.android:facebook-android-sdk:4.11.0'
    compile 'com.firebase:firebase-client-android:2.5.2'
    compile 'com.android.support:design:23.3.0'
}

这是我的Magpie java类:

package com.powerofpixels.magpie;


import android.app.Application;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Base64;
import android.util.Log;

import com.facebook.FacebookSdk;
import com.firebase.client.Firebase;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Tom Finet on 16/04/2016.
 */
public class Magpie extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        FacebookSdk.sdkInitialize(getApplicationContext());
        /* Initialize Firebase */
        Firebase.setAndroidContext(getApplicationContext());
        /* Enable disk persistence  */
        Firebase.getDefaultConfig().setPersistenceEnabled(true);

        // print out the key hash, to prevent hackers from accessing user information
        try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "com.powerofpixels.magpie",
                    PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
}

简而言之,logcat基本上说:

java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.powerofpixels.magpie.Magpie
Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.powerofpixels.magpie.Magpie
Caused by: java.lang.ClassNotFoundException: com.powerofpixels.magpie.Magpie
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.powerofpixels.magpie.Magpie" on path: DexPathList[[zip file "/data/app/com.powerofpixels.magpie-1/base.apk"],nativeLibraryDirectories=[/data/app/com.powerofpixels.magpie-1/lib/x86, /vendor/lib, /system/lib]]
Suppressed: java.lang.ClassNotFoundException: com.powerofpixels.magpie.Magpie
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.powerofpixels.magpie.Magpie`
Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.powerofpixels.magpie.Magpie
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/FacebookSdk;
at com.powerofpixels.magpie.Magpie.onCreate(Magpie.java:24)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.FacebookSdk" on path: DexPathList[[dex file "/data/data/com.powerofpixels.magpie/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.powerofpixels.magpie/files/instant-run/dex/slice-slice_1-classes.dex"],nativeLibraryDirectories=[/data/app/com.powerofpixels.magpie-1/lib/x86, /vendor/lib, /system/lib]]
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

关于如何帮助我取得进步的任何想法?感谢。

0 个答案:

没有答案