実現したいこと
ビルド時に起動はされるのですが、アプリが立ち上がらないです。
Logcatを確認したところエラーが発生していました。
アプリ立ち上げまでお力添えいただきたいです。
発生している問題・分からないこと
MainActivity クラスが見つからないとエラーで言われています。
※MainActivity.ktはcom.example.todoapp直下にあります。
エラーメッセージ
error
1FATAL EXCEPTION: main 2Process: com.example.todoapp, PID: 16874 3java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.todoapp/com.example.todoapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.todoapp.MainActivity" on path: DexPathList[[dex file "/data/data/com.example.todoapp/code_cache/.overlay/base.apk/classes3.dex", dex file 4 52024-04-22 23:26:36.164 16874-16874 AndroidRuntime com.example.todoapp E Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.todoapp.Hilt_MainActivity" on path: DexPathList[[dex file "/data/data/com.example.todoapp/code_cache/.overlay/base.apk/classes3.dex", dex file ... 20 more 6Suppressed: [CIRCULAR REFERENCE: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/todoapp/Hilt_MainActivity;] 72024-04-22 23:26:36.187 16874-16874 Process com.example.todoapp
該当のソースコード
[MainActivity.kt]
kotlin
1package com.example.todoapp 2 3import 省略 4 5@AndroidEntryPoint 6class MainActivity : ComponentActivity() { 7 override fun onCreate(savedInstanceState: Bundle?) { 8 super.onCreate(savedInstanceState) 9 setContent { 10 TodoAppTheme { 11 // A surface container using the 'background' color from the theme 12 Surface( 13 modifier = Modifier.fillMaxSize(), 14 color = MaterialTheme.colorScheme.background 15 ) { 16 } 17 } 18 } 19 } 20}
[AndroidManifest.xml]
xml
1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools"> 4 5 <application 6 android:name=".TodoApplication" 7 android:allowBackup="true" 8 android:dataExtractionRules="@xml/data_extraction_rules" 9 android:fullBackupContent="@xml/backup_rules" 10 android:icon="@mipmap/ic_launcher" 11 android:label="@string/app_name" 12 android:roundIcon="@mipmap/ic_launcher_round" 13 android:supportsRtl="true" 14 android:theme="@style/Theme.TodoApp" 15 tools:targetApi="31"> 16 <activity 17 android:name=".MainActivity" 18 android:exported="true" 19 android:label="@string/app_name" 20 android:theme="@style/Theme.TodoApp"> 21 <intent-filter> 22 <action android:name="android.intent.action.MAIN" /> 23 24 <category android:name="android.intent.category.LAUNCHER" /> 25 </intent-filter> 26 </activity> 27 </application> 28 29</manifest>
[build.gradle:app]
kotlin
1plugins { 2 id("com.android.application") 3 id("org.jetbrains.kotlin.android") 4 alias(libs.plugins.ksp.gradle.plugin) 5 alias(libs.plugins.hilt.android.gradle.plugin) 6} 7 8android { 9 namespace = "com.example.todoapp" 10 compileSdk = 34 11 12 defaultConfig { 13 applicationId = "com.example.todoapp" 14 minSdk = 24 15 targetSdk = 34 16 versionCode = 1 17 versionName = "1.0" 18 19 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 20 vectorDrawables { 21 useSupportLibrary = true 22 } 23 } 24 25 buildTypes { 26 release { 27 isMinifyEnabled = false 28 proguardFiles( 29 getDefaultProguardFile("proguard-android-optimize.txt"), 30 "proguard-rules.pro" 31 ) 32 } 33 } 34 compileOptions { 35 sourceCompatibility = JavaVersion.VERSION_1_8 36 targetCompatibility = JavaVersion.VERSION_1_8 37 } 38 kotlinOptions { 39 jvmTarget = "1.8" 40 } 41 buildFeatures { 42 compose = true 43 } 44 composeOptions { 45 kotlinCompilerExtensionVersion = "1.5.1" 46 } 47 packaging { 48 resources { 49 excludes += "/META-INF/{AL2.0,LGPL2.1}" 50 } 51 } 52} 53 54dependencies { 55 implementation(libs.androidx.core.ktx) 56 implementation(libs.androidx.lifecycle.runtime.ktx) 57 implementation(libs.androidx.activity.compose) 58 implementation(platform(libs.androidx.compose.bom)) 59 implementation(libs.androidx.ui) 60 implementation(libs.androidx.ui.graphics) 61 implementation(libs.androidx.ui.tooling.preview) 62 implementation(libs.androidx.material3) 63 testImplementation(libs.junit) 64 androidTestImplementation(libs.androidx.junit) 65 androidTestImplementation(libs.androidx.espresso.core) 66 androidTestImplementation(platform(libs.androidx.compose.bom)) 67 androidTestImplementation(libs.androidx.ui.test.junit4) 68 debugImplementation(libs.androidx.ui.tooling) 69 debugImplementation(libs.androidx.ui.test.manifest) 70 // hilt 71 implementation(libs.lifecycle.viewmodel.ktx) 72 implementation(libs.hilt.android) 73 ksp(libs.hilt.compiler) 74 implementation(libs.hilt.navigation.compose) 75 // room 76 implementation(libs.room.runtime) 77 implementation(libs.room.ktx) 78 annotationProcessor(libs.room.compiler) 79 ksp(libs.room.compiler) 80}
[build.gradle]
kotlin
1plugins { 2 alias(libs.plugins.androidApplication) apply false 3 alias(libs.plugins.jetbrainsKotlinAndroid) apply false 4 alias(libs.plugins.ksp.gradle.plugin) apply false 5 alias(libs.plugins.hilt.android.gradle.plugin) apply false 6}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
・MainActivity.kt ファイルは com.example.todoapp パッケージ内に存在しています
以下を実施しました
・Android Studioのキャッシュクリア「Invalidate Caches / Restart...」→再起動
・ビルドキャッシュをクリア「Build」→「Clean Project」
・プロジェクトの再構築「Build」→「Rebuild Project」
エラーは変わりませんでした。
補足
特になし

回答1件
あなたの回答
tips
プレビュー