我有一个应用程序,我有实现匕首,当午餐我的应用程序,我得到这个错误:-
FATAL EXCEPTION: main
Process: com.heet.sleepmagic, PID: 18977
java.lang.RuntimeException: Unable to instantiate application com.heet.sleepmagic.MainApp package com.heet.sleepmagic: java.lang.ClassNotFoundException: Didn't find class "com.heet.sleepmagic.MainApp" on path: DexPathList[[zip file "/data/app/~~vhnGOdaJiLk6ztERW8DzSg==/com.heet.sleepmagic-8TvtgzEu5imBuAIS-WXaGQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~vhnGOdaJiLk6ztERW8DzSg==/com.heet.sleepmagic-8TvtgzEu5imBuAIS-WXaGQ==/lib/x86_64, /system/lib64, /system_ext/lib64]]
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1466)
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1395)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6720)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.heet.sleepmagic.MainApp" on path: DexPathList[[zip file "/data/app/~~vhnGOdaJiLk6ztERW8DzSg==/com.heet.sleepmagic-8TvtgzEu5imBuAIS-WXaGQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~vhnGOdaJiLk6ztERW8DzSg==/com.heet.sleepmagic-8TvtgzEu5imBuAIS-WXaGQ==/lib/x86_64, /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.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1243)
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1458)
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1395)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6720)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/heet/sleepmagic/Hilt_MainApp;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 16 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.heet.sleepmagic.Hilt_MainApp" on path: DexPathList[[zip file "/data/app/~~vhnGOdaJiLk6ztERW8DzSg==/com.heet.sleepmagic-8TvtgzEu5imBuAIS-WXaGQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~vhnGOdaJiLk6ztERW8DzSg==/com.heet.sleepmagic-8TvtgzEu5imBuAIS-WXaGQ==/lib/x86_64, /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)
... 19 more
字符串
而我的构建.gradle是这样的:-
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id ("dagger.hilt.android.plugin")
}
android {
namespace = "com.heet.sleepmagic"
compileSdk = 34
defaultConfig {
applicationId = "com.heet.sleepmagic"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.8.0")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
// Compose dependencies
implementation ("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
implementation ("androidx.navigation:navigation-compose:2.7.4")
//Dagger - Hilt
implementation ("com.google.dagger:hilt-android:2.42")
annotationProcessor ("com.google.dagger:hilt-android-compiler:2.42")
annotationProcessor ("androidx.hilt:hilt-compiler:1.0.0")
implementation ("androidx.hilt:hilt-navigation-compose:1.0.0")
//Coil
implementation ("io.coil-kt:coil-compose:2.3.0")
}
型
而我的清单是这样的:
<?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:name=".MainApp"
android:theme="@style/Theme.SleepMagic"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.SleepMagic">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
型
我的申请类别:-
package com.heet.sleepmagic
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class MainApp:Application()
型
我的主活动:-
package com.heet.sleepmagic
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.sp
import androidx.navigation.compose.rememberNavController
import com.heet.sleepmagic.ui.navigation.Navigation
import com.heet.sleepmagic.ui.theme.HattonFontFamily
import com.heet.sleepmagic.ui.theme.HattonTypography
import com.heet.sleepmagic.ui.theme.SleepMagicTheme
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SleepMagicTheme {
Navigation(navController = rememberNavController())
}
}
}
}
型
这个错误是给我后,我更新了我的android工作室长颈鹿|2022.3.1我想这是因为匕首的职业问题或其他什么的。如果你能帮我解决这个问题,我将非常感激。谢谢。
我很感激你的回答。谢谢。
2条答案
按热度按时间bt1cpqcv1#
我得到了解决方案,这是因为我错误地实现了我的gradle文件,我不知道如何在Kotlin中添加依赖关系,所以我学习了它,并做了一些这样的改变,它解决了我的问题:-
字符串
我的build.gradle(app模块):-
型
我还得到了另一个错误,我必须将我的jvm版本从1.8更改为jvm 17:
型
bvjxkvbb2#
在您的AndroidManifest.xml中,您已经声明了一个
字符串
您需要拥有(或创建)一个扩展android.app.Application的类com.sleepmagic.MainApp。
或者干脆把线去掉。