java.lang.ClassNotFoundException on android app startup, using BUCK build tool

714 Views Asked by At

My app is crashing on startup because a class can't be found, however, I am confused about why that's happening because I've tested on two real devices where it doesn't crash on startup. This is the crash report I'm getting:

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

This is part of my 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" >

I do expect applogic.AppShell to run on the app startup, and to load the class applogic.PartageApplication, since this is what the build tool BUCK requires.

This is my class for 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);
    }
}

And this is the class that isn't found:

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

}

I would appreciate any help to figure out why this class can't be instantiated.

0

There are 0 best solutions below