我已经在我的项目中苦苦挣扎了几天,突然从一个构建/部署到另一个我开始得到以下异常。没有更新或更改,我只是想在发生时在其他设备上运行应用程序(就像其他任何一天一样)。
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
调试版本无法在我的所有3台设备(Android 5.0.2,6.0.1和7.0)和模拟器上部署/启动。 如果我选择两个或更多部署目标,运行可以工作,但不能只选择一个(因为多个目标禁用了即时运行)。 调试和运行在禁用即时运行时有效
我的项目有多种风格和applicationIds(如Android wear project with 3 flavors, 3 buildTypes and 2 applicationIdSuffixes中所示)。发生错误时没有更改任何gradle文件,清单也没有。
的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>
到目前为止,我已经尝试了以下内容:
非常感谢任何使用即时运行再次使用它的帮助!
答案 0 :(得分:4)
这似乎有时会启用即时运行(虽然在Android Studio的后续更新中不常见)。只需禁用即时运行,运行应用程序,再次启用即时运行。
希望即时运行能够不断改进。
(对我来说,在分支之间切换似乎更频繁地触发它。)
答案 1 :(得分:4)
它看起来像构建工具版本24.0.2中的一个错误,我升级到24.0.3并最终让它再次运行!
buildToolsVersion '24.0.3'
回滚到24.0.2每次都会重现问题。
答案 2 :(得分:0)
可能有多种原因。 如果您的问题是,当它从调试apk文件安装并且错误日志显示时,它无法在设备上运行应用程序:
java.lang.RuntimeException:无法实例化活动ComponentInfo java.lang.ClassNotFoundException:没找到类&#34; com.b.MainActivity&#34;在路径上:DexPathList
然后获得签名的apk 并在任何设备上运行,它将运行。
Android Studio&gt;构建&gt;生成签名APK