uPhyca / stetho-realm

Realm module for Stetho
Other
738 stars 114 forks source link

Unable to instantiate application app.DebugApplication: java.lang.ClassNotFoundException #70

Closed Drjacky closed 6 years ago

Drjacky commented 6 years ago

I've used this tutorial: http://littlerobots.nl/blog/stetho-for-android-debug-builds-only/ to use Stetho in debug build only. I have 2 custom classes which extended Application:

public class SecondCustomApplication extends FirstCustomApplication {

And

public class FirstCustomApplication extends MultiDexApplication {

Now the Debug class:

public class DebugApplication extends SecondCustomApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        Stetho.initialize(
                Stetho.newInitializerBuilder(this)
                        .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                        .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
                        .build());
    }
}

And in main AndroidManifest.xml:

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

<application
        android:name=".SecondCustomApplication"
        android:allowBackup="true"
        android:fullBackupContent="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:replace="icon,label,name">

And in debug AndroidManifest.xml:

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

    <application
        android:name="DebugApplication"
        tools:replace="name" />

</manifest>

But when I run the App, I get this error:

com.package.name E/AndroidRuntime: FATAL EXCEPTION: main Process: com.package.name, PID: 14078 java.lang.RuntimeException: Unable to instantiate application com.package.name.DebugApplication: java.lang.ClassNotFoundException: Didn't find class "com.package.name.DebugApplication" on path: DexPathList[[zip file "/data/app/com.package.name-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.package.name-1, /vendor/lib, /system/lib]] at android.app.LoadedApk.makeApplication(LoadedApk.java:516) ... Caused by: java.lang.ClassNotFoundException: Didn't find class "com.package.name.DebugApplication" on path: DexPathList[[zip file "/data/app/com.package.name-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.package.name-1, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at android.app.Instrumentation.newApplication(Instrumentation.java:975) at android.app.LoadedApk.makeApplication(LoadedApk.java:511)

ghost commented 6 years ago

I think this is because your class "DebugApplication" isn't on the main directory and in your debug Manifest you should use android:name=".DebugApplication"

The only thing wich you need in your debug directory is your debug Manifest.

kostyabakay commented 6 years ago

I have the same problem.

Drjacky commented 6 years ago