Reputation: 308
I see a lot of questions like this but none of them helped me to solve the issue. What's my issue is Android Studio able to build apk successfully but when I run it on my device it crashes.
java.lang.RuntimeException: Unable to instantiate application io.tutorial.app.App: java.lang.ClassNotFoundException: Didn't find class "io.tutorial.app.App" on path: DexPathList[[zip file "/data/app/io.tutorial.app-1/base.apk"],nativeLibraryDirectories=[/data/app/io.tutorial.app-1/lib/arm64, /data/app/io.tutorial.app-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:811)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5504)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1611)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6375)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.tutorial.app.App" on path: DexPathList[[zip file "/data/app/io.tutorial.app-1/base.apk"],nativeLibraryDirectories=[/data/app/io.tutorial.app-1/lib/arm64, /data/app/io.tutorial.app-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:74)
And below is the part of manifest file.
<application
android:theme="@style/AppTheme"
android:label="@string/app_name"
android:icon="@mipmap/ic_app"
android:name="io.tutorial.app.App"
android:allowBackup="true"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:theme="@style/AppTheme.NoActionBarFullScreen"
android:name=".ui.activity.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Instant run is turned off. Tested after invalidating caches and rebuild project. Generated signed APK and tried but same issue. I used analyze APK in Android Studio and I found there are two dex files 1.classes.dex 2. classes2.dex.
Below is the Part code of App.java class
public class App extends MultiDexApplication {
@Inject
Cache cache;
public void onCreate() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
super.onCreate();
initRemoteConfig();
Injector.getInstance().init(this);
Injector.getInstance().appComponent().inject(this);
initFabric();
initRealm();
initPicasso();
initRemoteConfig();
initAds();
initOneSignal();
}
Upvotes: 0
Views: 668
Reputation: 8843
If you have any class that is extending default Application class then change it as below
public class App extends MultiDexApplication
or you override attachBaseContext as below:
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Upvotes: 1