Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not available with Hilt #26

Open
kaki2015 opened this issue Jun 23, 2022 · 3 comments
Open

Not available with Hilt #26

kaki2015 opened this issue Jun 23, 2022 · 3 comments
Assignees

Comments

@kaki2015
Copy link

kaki2015 commented Jun 23, 2022

I want to use your library with together the hilt(DI Library).
But, I encountered an error Unable to instantiate application com.example.myapplication.MainApplication.
Doesn't recognize the Application Class(MainApplication) when building.
please help me, thx.

Reproduction

  1. Create a new Project with defalt.(Empty Compose Activity)
  2. Add the settings at build.gradle (Project: My_Application).
buildscript {

    // Add the following
    repositories {
        google()
        maven { url "https://plugins.gradle.org/m2/" }
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.1'
        classpath 'org.aspectj:aspectjtools:1.9.6'
        classpath 'com.ibotta:plugin:1.2.0'
    }
  1. Add the settings at build.gradle (Module: My_Application.app).
plugins {
    // Add the following
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
    id 'com.ibotta.gradle.aop'
}

Add the implementations.

// aspectj
implementation 'org.aspectj:aspectjrt:1.9.6'
// Hilt
implementation 'com.google.dagger:hilt-android:2.40.1'
kapt 'com.google.dagger:hilt-android-compiler:2.40.1'
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
  1. Create the Application Class.
class MainApplication : Application()

Add android:name="com.example.myapplication.MainApplication" at AndroidManifest.xml.

<?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.aoptestapplication">

    <application
        android:name="com.example.myapplication.MainApplication" // add
  1. Build OK
  2. Add the @HiltAndroidApp
@HiltAndroidApp // add 
class MainApplication : Application()
  1. Run the app.
    Unable to instantiate application com.example.myapplication.MainApplication: java.lang.ClassNotFoundException:
2022-06-23 10:26:09.881 18954-18954/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication, PID: 18954
    java.lang.RuntimeException: Unable to instantiate application com.example.myapplication.MainApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.myapplication.MainApplication" on path: DexPathList[[zip file "/data/app/com.example.myapplication-ytHMBpWkgDmYGcXCZ6NxFg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-ytHMBpWkgDmYGcXCZ6NxFg==/lib/arm64, /system/lib64, /system/product/lib64]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1226)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431)
        at android.app.ActivityThread.access$1300(ActivityThread.java:219)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myapplication.MainApplication" on path: DexPathList[[zip file "/data/app/com.example.myapplication-ytHMBpWkgDmYGcXCZ6NxFg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-ytHMBpWkgDmYGcXCZ6NxFg==/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:1148)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1218)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431) 
        at android.app.ActivityThread.access$1300(ActivityThread.java:219) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
    	Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/myapplication/Hilt_MainApplication;
        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.myapplication.Hilt_MainApplication" on path: DexPathList[[zip file "/data/app/com.example.myapplication-ytHMBpWkgDmYGcXCZ6NxFg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-ytHMBpWkgDmYGcXCZ6NxFg==/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
@vdelricco vdelricco self-assigned this Jun 24, 2022
@vdelricco
Copy link
Contributor

Thanks for the issue submission @kaki2015, will report back with my findings 👀

@vdelricco
Copy link
Contributor

Hi @kaki2015, in the project you were attempting to add Hilt, could you try adding the following to the project build.gradle file:

hilt {
    enableAggregatingTask = false
    enableExperimentalClasspathAggregation = true
}

In my repro setup, this caused the app to behave properly. This uses a flag which is marked deprecated so there might be some more investigation to be done here but I was wanted to see if it also solves the problem for you.

@Sunar
Copy link

Sunar commented Sep 9, 2022

@vdelricco I've encountered same error and that setup for Hilt fixed the problem. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants