I am creating an app with Android Studio that crashes when I run it on my OnePlus N200 5G device. The name of the package is com.example.chapter3.
Android Application/Library Version: 8.0.2
OnePlus N200 5G Version: 12
Kotlin Version: 1.7.2
The code is below in a MainActivity.kt file:
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApp()
}
}
}
@Composable
fun MyApp() {
var count by remember() { mutableStateOf(0) }
Column(
modifier=Modifier.padding(16.dp)
){
Text(text = "Counter: $count", style = MaterialTheme.typography.bodyLarge)
Spacer(modifier=Modifier.height(16.dp))
Button(onClick = { count++ }) {
Text("Increment")
}
}
}
The manifest is below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
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.Chapter3"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Chapter3">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The errors from the logcat are below:
Unable to open '/data/data/com.example.chapter3/code_cache/.overlay/base.apk/classes2.dm': No such file or directory
Unable to open '/data/app/~~-viv8utqhkYTZoznAoSHqA==/com.example.chapter3-XWzS_aPEYxw4grWM96M0Pw==/base.dm': No such file or directory
Unable to open '/data/app/~~-viv8utqhkYTZoznAoSHqA==/com.example.chapter3-XWzS_aPEYxw4grWM96M0Pw==/base.dm': No such file or directory
FATAL EXCEPTION: main
Process: com.example.chapter3, PID: 15473
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.chapter3/com.example.chapter3.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.chapter3.MainActivity" on path: DexPathList[[dex file "/data/data/com.example.chapter3/code_cache/.overlay/base.apk/classes2.dex", zip file "/data/app/~~-viv8utqhkYTZoznAoSHqA==/com.example.chapter3-XWzS_aPEYxw4grWM96M0Pw==/base.apk"],nativeLibraryDirectories=[/data/app/~~-viv8utqhkYTZoznAoSHqA==/com.example.chapter3-XWzS_aPEYxw4grWM96M0Pw==/lib/arm64, /system/lib64, /system_ext/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3682)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3942)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:109)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2345)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:233)
at android.os.Looper.loop(Looper.java:344)
at android.app.ActivityThread.main(ActivityThread.java:8212)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.chapter3.MainActivity" on path: DexPathList[[dex file "/data/data/com.example.chapter3/code_cache/.overlay/base.apk/classes2.dex", zip file "/data/app/~~-viv8utqhkYTZoznAoSHqA==/com.example.chapter3-XWzS_aPEYxw4grWM96M0Pw==/base.apk"],nativeLibraryDirectories=[/data/app/~~-viv8utqhkYTZoznAoSHqA==/com.example.chapter3-XWzS_aPEYxw4grWM96M0Pw==/lib/arm64, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1288)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3669)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3942)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:109)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2345)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:233)
at android.os.Looper.loop(Looper.java:344)
at android.app.ActivityThread.main(ActivityThread.java:8212)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
After reading similar posts,
- I do not understand what a MultiDex is, nor whether it is relevant to this error
- I put the MainActivity file in the manifest, so I am not sure why the system does not see it
- I do not know why the ziparchive cannot open the said files and whether that is relevant to this error
I lack a lot of the context for this and the textbook I am using has absolutely no information on the issues I am facing. Please help me contextualize this.
4