android app启动时的java.lang.ClassNotFoundException,使用BUCK构建工具

时间:2015-08-23 01:29:38

标签: android buck

我的应用程序在启动时崩溃,因为无法找到一个类,但是,我很困惑为什么会发生这种情况,因为我已经在两个真正的设备上进行了测试,它们在启动时没有崩溃。这是我得到的崩溃报告:

java.lang.RuntimeException: Unable to instantiate application applogic.AppShell: java.lang.RuntimeException: java.lang.ClassNotFoundException: applogic.PartageApplication
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4588)
at android.app.ActivityThread.access$1600(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: applogic.PartageApplication
at com.facebook.buck.android.support.exopackage.ExopackageApplication.createDelegate(ExopackageApplication.java:84)
at com.facebook.buck.android.support.exopackage.ExopackageApplication.ensureDelegate(ExopackageApplication.java:90)
at com.facebook.buck.android.support.exopackage.ExopackageApplication.attachBaseContext(ExopackageApplication.java:114)
at android.app.Application.attach(Application.java:201)
at android.app.Instrumentation.newApplication(Instrumentation.java:997)
at android.app.Instrumentation.newApplication(Instrumentation.java:981)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
Caused by: java.lang.ClassNotFoundException: applogic.PartageApplication
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at com.facebook.buck.android.support.exopackage.ExopackageApplication.createDelegate(ExopackageApplication.java:80)
... 17 more
Caused by: java.lang.NoClassDefFoundError: applogic/PartageApplication
... 21 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "applogic.PartageApplication" on path: DexPathList[[zip file "/data/app/co.partage.partage-1.apk"],nativeLibraryDirectories=[/data/app-lib/co.partage.partage-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
... 21 more

这是我的AndroidManifest.xml的一部分:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionName="1.0"
    android:versionCode="1"
    package="co.partage.partage" >

    <application
        android:name="applogic.AppShell"
        android:allowBackup="true"
        android:icon="@mipmap/app_icon"
        android:label="@string/app_name"
        android:hardwareAccelerated="true"
        android:theme="@style/AppTheme" >

我确实期望applogic.AppShell在应用启动时运行,并加载类applogic.PartageApplication,因为这是构建工具BUCK所需要的。

这是我的AppLogic课程:

public class AppShell extends ExopackageApplication {

    public AppShell() {
        super(
        // This is passed as a string so the shell application does not
        // have a binary dependency on your ApplicationLike class.
        /* applicationLikeClassName */ "applogic.PartageApplication",

        // The package for this BuildConfig class must match the package
        // from the android_build_config() rule. The value of the flags
        // will be set based on the "exopackage_modes" argument to
        // android_binary().
        co.partage.partage.BuildConfig.EXOPACKAGE_FLAGS);
    }
}

这是找不到的课程:

package applogic;

...

public class PartageApplication extends DefaultApplicationLike {
    private static Context context;

    public PartageApplication(Application application) {
        context = application;
    }

    public void onCreate() {
        super.onCreate();
        FacebookSdk.sdkInitialize(context);
        final Thread.UncaughtExceptionHandler defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
        java.lang.Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable ex) {

                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                ex.printStackTrace(pw);
                String stackTrace = sw.toString(); // stack trace as a string

                Intent intent = new Intent(getAppContext(), LogDebug.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("message", ex.getMessage());
                intent.putExtra("stackTrace", stackTrace);
                getAppContext().startActivity(intent);

                // kill the error thread
                System.exit(10);
                throw new RuntimeException("app crash");
            }
        });
    }


    public static Context getAppContext() {
        return PartageApplication.context;
    }

}

我很感激任何帮助,以弄清楚为什么这个类无法实例化。

0 个答案:

没有答案