I've been struggling with my project for a few days now, suddenly from one build/deploy to another I started getting the following exception. Nothing was updated or changed, I just wanted to run the app on a different device when it happened (just like any other day really).
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.my.app.flavor.debug/com.my.app.ui.activity.WelcomeActivity}: java.lang.ClassNotFoundException: Didn't find class "com.my.app.flavor.ui.activity.WelcomeActivity" on path: DexPathList[[zip file "/data/app/com.my.app.flavor.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/**com.my.app.flavor.**debug-2/lib/x86, /data/app/com.my.app.flavor.debug-2/base.apk!/lib/x86, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.my.app.ui.activity.WelcomeActivity" on path: DexPathList[[zip file "/data/app/com.my.app.flavor.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app.flavor.debug-2/lib/x86, /data/app/com.my.app.flavor.debug-2/base.apk!/lib/x86, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.ClassNotFoundException: com.my.app.ui.activity.WelcomeActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Debug builds fail to deploy/start on all my 3 devices (Android 5.0.2, 6.0.1 and 7.0), and on emulators. Run works if I select two or more deployment targets, but not with only one (because instant run is disabled with multiple targets). Debug and Run works when instant run is disabled
My project has multiple flavors and applicationIds (like in Android wear project with 3 flavors, 3 buildTypes and 2 applicationIdSuffixes). None of the gradle files were changed when the error occured, neither was the manifest.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
package="com.my.app">
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<!-- PROTECTION_NORMAL -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- PROTECTION_DANGEROUS -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- Protection unknown -->
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-feature android:name="android.hardware.location" android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name="net.hockeyapp.android.UpdateActivity" />
<activity
android:name=".ui.activity.WelcomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activity.StartActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" />
<activity
android:name="com.facebook.LoginActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activity.NotificationActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activity.OtherActivity"
android:label="@string/cards_register_card"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activity.OneMoreActivity"
android:label="@string/a_title"
android:parentActivityName=".ui.activity.OtherActivity"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.activity.OtherActivity" />
</activity>
<service android:name=".service.WearableListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data
android:host="*"
android:pathPrefix="/path"
android:scheme="wear" />
</intent-filter>
</service>
<!-- GCM START -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<service
android:name=".service.PushListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".service.PushInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name=".service.PushRegistrationIntentService"
android:exported="false"></service>
<!-- GCM END -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_api_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<!-- Register AnalyticsReceiver and AnalyticsService to support background dispatching on non-Google Play devices -->
<receiver
android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false" />
</application>
So far I've tried the following:
- clean, clean, clean and even more cleaning
- delete all /build folders
- restarting Android Studio (2.2), my computer and all devices
- uninstalling all flavors of my apps on all devices and emulators
- trying to create a new Run configuration with the activity specified under Launch Options (sometimes works when running on a single deployment target, but never in Debug mode)
- running with instant run deactivated followed by a run with it activated
- re-installing Android Studio
Any help on getting this to work again with instant run is much appreciated!
gradlew -d assembleDebug
if no error pop out, may be and Android Studio bug, sometimes i face problems like yours, try turn off the Instant run feature if you have. – Yocumgradlew -d assembleDebug
builds fine, no errors. Turning off instant run actually lets me debug (thx!), but how to get it working with instant run again? – Messer