Crashing app when launching,
Update Gradle plugin 4.x.x to 7.0.4 and Migrate Dagger2 to Hilt.
And update Kotlin to 1.6.0.
Added @@HiltAndroidApp
on the Application class.
Apply Multidex but not working.
Try some other solutions but not helped.
Please see the log.
tech.xyz.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: tech.xyz.android, PID: 14295
java.lang.RuntimeException: Unable to instantiate application tech.xyz.android.base.BaseApplication package tech.xyz.android: java.lang.ClassNotFoundException: Didn't find class "tech.xyz.android.base.BaseApplication" on path: DexPathList[[zip file "/data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/base.apk"],nativeLibraryDirectories=[/data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/lib/arm64, /data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64, /product/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1364)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6689)
at android.app.ActivityThread.access$1500(ActivityThread.java:247)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2057)
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:7842)
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:1003)
Caused by: java.lang.ClassNotFoundException: Didn't find class "tech.xyz.android.base.BaseApplication" on path: DexPathList[[zip file "/data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/base.apk"],nativeLibraryDirectories=[/data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/lib/arm64, /data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
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:1177)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1356)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6689)
at android.app.ActivityThread.access$1500(ActivityThread.java:247)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2057)
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:7842)
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:1003)
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Ltech/xyz/android/base/Hilt_BaseApplication;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 15 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "tech.xyz.android.base.Hilt_BaseApplication" on path: DexPathList[[zip file "/data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/base.apk"],nativeLibraryDirectories=[/data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/lib/arm64, /data/app/~~GzEkuyUrT68SI_tbzjNEGg==/tech.xyz.android-puNWBMfhZZkc5IKFz18ZHA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 18 more
After update gradle, kotlin and add hilt into root-level Gradle:
buildscript {
ext{
kotlin_version = "1.6.0"
apollo_version = '2.5.10'
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
classpath "com.apollographql.apollo:apollo-gradle-plugin:$apollo_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is the Application class:
@HiltAndroidApp
class BaseApplication : Application(), LifecycleObserver {
private val TAG = "BaseApplication"
companion object {
lateinit var instance: BaseApplication
private set
}
override fun attachBaseContext(base: Context?) {
// MultiDex.install(base)
super.attachBaseContext(base)
}
override fun onCreate() {
ActivityLifecycleCallback.register(this)
super.onCreate()
instance = this
userAgent = Util.getUserAgent(this, "AdaptiveExoplayer")
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)
ProcessLifecycleOwner.get()
.lifecycle
.addObserver(this)
}
}
Here is the <application>
tag of AndroidManifest.xml
<application
android:name=".base.BaseApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_config"
android:largeHeap="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
Most of the solutions say to add Multidex or clean and rebuild project or invalidate cache and restart. Try most of the solutions but didn't help.
CodePudding user response:
Try changing your manifest from:
android:name=".base.BaseApplication"
to:
android:name="tech.xyz.android.base.BaseApplication"
CodePudding user response:
The problem was in my module-level gradle file. I was used annotationProcessor
instead of kapt
.
annotationProcessor 'com.google.dagger:hilt-compiler:2.40.5'
Then changed it into
kapt 'com.google.dagger:hilt-compiler:2.40.5'