I am trying to create an app to block the installation of a certain app based on the package name. I tried the BroadcastReceiver method but the app seems to crash. and thank you for reviewing this and for the help.
here is my BroadcastReceiver class:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class MyReceiver extends BroadcastReceiver {
Context context;
String log = MyReceiver.class.getName();
#Override
public void onReceive(Context context, Intent intent) {
this.context = context;
if(intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")){
Toast.makeText(context,"Package removed", Toast.LENGTH_LONG).show();
Log.d(log,"Package removed");
}
if(intent.getAction().equals("android.intent.action.PACKAGE_ADDED")){
Toast.makeText(context, "Package installed", Toast.LENGTH_SHORT).show();
Log.d(log,"Package installed");
}
}
}
manifest:
<receiver
android:name="MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
crash log:
10-12 22:18:22.836 15429-15429/com.example.mohammed.broadcastreceiver E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mohammed.broadcastreceiver, PID: 15429
java.lang.RuntimeException: Unable to instantiate receiver com.example.mohammed.broadcastreceiver.MyReceiver: java.lang.ClassNotFoundException: Didn't find class "com.example.mohammed.broadcastreceiver.MyReceiver" on path: DexPathList[[zip file "/data/app/com.example.mohammed.broadcastreceiver-1/base.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.mohammed.broadcastreceiver-1/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3287)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1719)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.mohammed.broadcastreceiver.MyReceiver" on path: DexPathList[[zip file "/data/app/com.example.mohammed.broadcastreceiver-1/base.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.mohammed.broadcastreceiver-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.mohammed.broadcastreceiver-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3282)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1719)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
You've registered your Receiver incorrectly.
The crash log says it can't find MyReceiver in the root of your project (which is where you've said it exists in your Manifest), but it looks like it isn't.
Make sure the name attribute points to the actual location.
Related
I am getting following error with android 10. Although i tried with my device having android 10, everything is working fine but Google crashlytics showing number of crash.
Fatal Exception: java.lang.RuntimeException
Unable to get provider androidx.core.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "androidx.core.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.xyz-MraZIoKhOLuyDHnQOgA2Cg==/base.apk", zip file "/data/app/com.xyz-MraZIoKhOLuyDHnQOgA2Cg==/split_config.arm64_v8a.apk", zip file "/data/app/com.xyz-MraZIoKhOLuyDHnQOgA2Cg==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.xyz-MraZIoKhOLuyDHnQOgA2Cg==/lib/arm64, /data/app/com.xyz-MraZIoKhOLuyDHnQOgA2Cg==/base.apk!/lib/arm64-v8a, /data/app/com.xyz-MraZIoKhOLuyDHnQOgA2Cg==/split_config.arm64_v8a.apk!/lib/arm64-v8a, /data/app/com.xyz-MraZIoKhOLuyDHnQOgA2Cg==/split_config.xxhdpi.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
Fatal Exception: java.lang.RuntimeException: Unable to get provider androidx.core.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "androidx.core.content.FileProvider" on path: DexPathList[[zip file "/data/app/-MraZIoKhOLuyDHnQOgA2Cg==/base.apk", zip file "/data/app/c-MraZIoKhOLuyDHnQOgA2Cg==/split_config.arm64_v8a.apk", zip file "/data/app/-MraZIoKhOLuyDHnQOgA2Cg==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/-MraZIoKhOLuyDHnQOgA2Cg==/lib/arm64, /data/app-MraZIoKhOLuyDHnQOgA2Cg==/base.apk!/lib/arm64-v8a, /data/app/-MraZIoKhOLuyDHnQOgA2Cg==/split_config.arm64_v8a.apk!/lib/arm64-v8a, /data/app/MraZIoKhOLuyDHnQOgA2Cg==/split_config.xxhdpi.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
at android.app.ActivityThread.installProvider(ActivityThread.java:7443)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6935)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6852)
at android.app.ActivityThread.access$1600(ActivityThread.java:242)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7830)
at java.lang.reflect.Method.invoke(Method.java)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1040)
Have you registered your provider in the AndroidManifest.xml file?
as it is said in docs
If Yes, you will need to provide more information about how you work with the FileProvider class
I am trying to implement Dagger hilt in my project for dependencies injection. I have
MyApplication class which extends Application ,I have added this app in manifest.xml file too ,When I build the code every thing works fine, but when I run it my app crashes with below errors. It throws run time exception with class not found exception .
Error
2022-07-13 18:30:42.953 23036-23036/? E/pendencieinjec: Unknown bits set in runtime_flags: 0x28000
2022-07-13 18:30:43.414 23036-23036/com.example.dependencieinject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dependencieinject, PID: 23036
java.lang.RuntimeException: Unable to instantiate application com.example.dependencieinject.MyApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.dependencieinject.MyApplication" on path: DexPathList[[zip file "/data/app/com.example.dependencieinject-BKvqDel8fkOj55VnLfhHLw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dependencieinject-BKvqDel8fkOj55VnLfhHLw==/lib/arm64, /system/lib64, /system/product/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1230)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6533)
at android.app.ActivityThread.access$1400(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1886)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:221)
at android.app.ActivityThread.main(ActivityThread.java:7542)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.dependencieinject.MyApplication" on path: DexPathList[[zip file "/data/app/com.example.dependencieinject-BKvqDel8fkOj55VnLfhHLw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dependencieinject-BKvqDel8fkOj55VnLfhHLw==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1156)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1222)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6533)
at android.app.ActivityThread.access$1400(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1886)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:221)
at android.app.ActivityThread.main(ActivityThread.java:7542)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/dependencieinject/Hilt_MyApplication;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 14 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.dependencieinject.Hilt_MyApplication" on path: DexPathList[[zip file "/data/app/com.example.dependencieinject-BKvqDel8fkOj55VnLfhHLw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dependencieinject-BKvqDel8fkOj55VnLfhHLw==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 17 more
Manifest
<?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.example.dependencieinject">
<application
android:name=".MyApplication"
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.DependencieInject"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MyApplication
package com.example.dependencieinject
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
#HiltAndroidApp
class MyApplication:Application() {
}
Main ACTIVITY
package com.example.dependencieinject
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
#AndroidEntryPoint
class MainActivity : AppCompatActivity() {
#Inject
lateinit var userRegistration: UserRegistration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
userRegistration.registerUser("roshan#g.c","Roshan nepal")
}
}
UserRegisteration
package com.example.dependencieinject
import android.util.Log
import javax.inject.Inject
const val TAG="UserRegistration"
class UserRegistration #Inject constructor(){
fun registerUser(email:String,name:String){
Log.d(TAG, "User Registration code running ")
Log.d(TAG, "User Registered ")
}
}
This question already has answers here:
Android app ClassNotFoundException for main activity
(13 answers)
Closed 12 months ago.
I am trying to build a app with Google API and i followed every steps that was given on internet to how to work with Google API, but when i run my app it launch and then closes instantly.
Logcat
04-21 19:07:19.857 16778-16778/? I/art: Late-enabling -Xcheck:jni
04-21 19:07:19.858 16778-16778/? I/art: Reinit property: dalvik.vm.checkjni= false
04-21 19:07:20.052 16778-16778/com.example.kakarot.cpecroute W/System: ClassLoader referenced unknown path: /data/app/com.example.kakarot.cpecroute-1/lib/arm64
04-21 19:07:20.065 16778-16778/? I/InstantRun: starting instant run server: is main process
04-21 19:07:20.074 16778-16778/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.kakarot.cpecroute, PID: 16778
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.kakarot.cpecroute/com.example.kakarot.cpecroute.MapsActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.kakarot.cpecroute.MapsActivity" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.kakarot.cpecroute-1/base.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.kakarot.cpecroute-1/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2698)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2870)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1573)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6605)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:999)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:889)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.kakarot.cpecroute.MapsActivity" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.kakarot.cpecroute-1/base.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.kakarot.cpecroute-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.kakarot.cpecroute-1/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2688)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2870)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1573)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6605)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:999)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:889)
04-21 19:07:20.083 16778-16778/? I/Process: Sending signal. PID: 16778 SIG: 9
.............................................................................
AndroidManifest.xml/activity
#Sagar Yes, there is a activity in AndroidManifest.xml.
Below is code
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Try this :
<activity android:name="com.yourpackagename.MapsActivity" android:label="#string/title_activity_maps"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
Let me know is this works or not
I have resolved this issue by upgrading my Gradle plugin version to 7.1.1:
classpath 'com.android.tools.build:gradle:7.1.1'
I believe what is causing it is a stack trace.
I am going through the official Android app bulding tutorial here: https://developer.android.com/training/index.html
I finished the "Start Another Activity" section and have found this error while trying to test it. I was also not able to run the app in the earlier parts of the tutorial.
That led me to this link: Unfortunately MyApp has stopped. How can I solve this?
Which led me to this link:
What is a stack trace, and how can I use it to debug my application errors?
But I am still having trouble figuring it out.
Here is a snippet of the error log:
12-14 09:52:06.962 3696-3696/com.example.myfirstapp I/zygote: at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
12-14 09:52:06.962 3696-3696/com.example.myfirstapp I/zygote: at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:438)
12-14 09:52:06.962 3696-3696/com.example.myfirstapp I/zygote: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:807)
12-14 09:52:06.962 3696-3696/com.example.myfirstapp D/AndroidRuntime: Shutting down VM
12-14 09:52:06.964 3696-3696/com.example.myfirstapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myfirstapp, PID: 3696
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myfirstapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/base.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/lib/x86, /system/lib, /vendor/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myfirstapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/base.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
12-14 09:52:06.964 3696-3696/com.example.myfirstapp E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 12 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatActivity" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/base.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myfirstapp-R68LcIdIMck0utpOhrKfsA==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 15 more
Any suggestions on how to figure this out? Thanks!
Edit:
I believe this is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisplayMessageActivity"
android:parentActivityName=".MainActivity" >
<!-- The meta-data tag is required if you support API level 15 and lower -->
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
You have incorrect closing tag in your manifest:
<activity android:name=".DisplayMessageActivity"
android:parentActivityName=".MainActivity" >
<!-- The meta-data tag is required if you support API level 15 and lower -->
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
This is the incorrect closing tag without open tag:
<!-- The meta-data tag is required if you support API level 15 and lower -->
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
Try removing it.
UPDATED:
From the tutorial, you're missing the open tag of <meta-data, so you need to correct it by adding the open tag:
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" />
After adding the tag, your code will be like this:
<activity android:name=".DisplayMessageActivity"
android:parentActivityName=".MainActivity" >
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
I have a published app that gets reports about a ClassNotFoundExceptionfrom users that I went beyond my wits end trying to fix. I have not been able to reproduce this crash and similar instances of this error here on SO have either been cases of incorrect path to a dependency or a different package in the MainActivity than the manifest.
The issues with the wrong path to the dependencies are an Eclipse thing, while all the other errors could be easily fixed with Android Studio's "sync" and "clean project" (which I did to no avail).
I've triple checked all the package names and did not find any discrepancies.
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.johan.fsc">
<uses-permission android:name = "android.permission.VIBRATE"/>
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:fullBackupContent="true">
<activity
android:name="com.johan.fsc.MainActivity"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:theme="#style/splashscreenTheme"
android:hardwareAccelerated="false"
android:largeHeap="true">>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name = "com.johan.fsc.SettingsActivity"
android:theme="#style/PreferencesTheme"/>
</application>
Here is the error report I always get from users:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.johan.fsc/com.johan.fsc.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.johan.fsc.MainActivity" on path: DexPathList[[zip file "/data/app/com.johan.fsc-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.johan.fsc.MainActivity" on path: DexPathList[[zip file "/data/app/com.johan.fsc-1/base.apk"],nativeLibraryDirectories=[/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:1071)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
... 10 more
Suppressed: java.io.IOException: Failed to open oat file from dex location '/data/app/com.johan.fsc-1/base.apk'
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:295)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexFile.<init>(DexFile.java:59)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:262)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:231)
at dalvik.system.DexPathList.<init>(DexPathList.java:109)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:57)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:370)
at android.app.LoadedApk.makeApplication(LoadedApk.java:562)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4818)
at android.app.ActivityThread.access$1500(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1531)
... 7 more
Caused by: java.io.IOException: Failed to open oat file from /data/app/com.johan.fsc-1/arm/base.odex (error Failed to open oat filename for reading: No such file or directory) (no dalvik_cache availible) and relocation failed.
... 22 more
Caused by: java.io.IOException:
... 22 more
Caused by: java.io.IOException: Failed to remove obsolete file from /data/dalvik-cache/arm/data#app#com.johan.fsc-1#base.apk#classes.dex when searching for dex file /data/app/com.johan.fsc-1/base.apk: Permission denied
... 22 more
Suppressed: java.lang.ClassNotFoundException: com.johan.fsc.MainActivity
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)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available/output.
It would seem that the culprit is java.io.IOException: Failed to remove obsolete file from /data/dalvik-cache/arm/data#app#com.johan.fsc-1#base.apk#classes.dex when searching for dex file /data/app/com.johan.fsc-1/base.apk: Permission denied, but I have not found why it's being invoked for some users and not the majority, and more importantly--how to fix it.
Possible Cause 1: There is a typo in the manifest in the line android:largeHeap="true">>. xml line ends with >>. This may be preventing the Intent-Filter from executing.
Possible Cause 2: My guess is that the phone is searching for a class <PackageName>.<PackageName>.<ClassName> instead of <PackageName>.<ClassName> . So definitely <PackageName>.<PackageName>.<ClassName> is not found and ClassNotFoundException would be the result. In android studio, in the manifest, by default activity name is written like this: android:name=".<ClassName>" instead of android:name="<PackageName>.<ClassName>" . You can give this a try.
Most phones may be checking whether packagename is added before the class name in the manifest. If it is added then they don't add it while searching of the class. While few phones must be adding the package name by default while searching for the class. Hence, they cannot find your class.
Certainly, you're naming your activity wrong. An activity CAN NOT consist the package's name in its name attribute.
Since you're already defining the package name here
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.johan.fsc">
You shouldn't mention that name here
<activity android:name="com.johan.fsc.MainActivity"
The only situation you should use package name along with a class's name is when the java class resides in a different package, as done in import statements.
Even if your activity is not present in the src folder and is instead present in a nested folder, android studio should handle the linking of manifest and the activity itself. Yet again, package name shouldn't be used there.