Giter VIP home page Giter VIP logo

Comments (6)

wanyingd1996 avatar wanyingd1996 commented on June 12, 2024

Hi, dagger ships an r8 rule -identifiernamestring that comes with the usage of @LazyClassKey, you shouldn't need to do anything else to make that work. What is the version of R8 you are using? Maybe identifiernamestring isn't included in an earlier version of R8. If version update doesn't help, can you provide a repro for the problem. I copied your example into our sample r8 app, and it build and runs successfully.

from dagger.

nitinsethi86 avatar nitinsethi86 commented on June 12, 2024

Can you point me to the exact rule you are talking about?
I use the R8 version 8.2.47 that ships with AGP 8.2.2.

I came up with a solution to make all Class used as class key implement a marker interface called LazyClassKeyable. Once we do that, the below R8 rule will work for all keys.

# Keep rule for supporting LazyClassKey
-keep class * implements com.microsoft.teams.injection.LazyClassKeyable { *; }

With a unit test, we can force future additions to implement the marker interface LazyClassKeyable. I was thinking of writing a unit tests that gets holds of all keys and assert that they can be assigned to LazyClassKeyable.

    @Test
    fun appDataFactory_mapKeys_shouldBeLazyClassKeyable() {
        val app = context as StubbedSkypeTeamsApplication
        val userDataFactory : UserDataFactory = app.getUserDataFactory(TEST_USER_OBJECT_ID)
        assertEquals("Note: New key added to multibinding UserDataFactoryMap needs to implement LazyClassKeyable.",251, userDataFactory.mProviderMap.size)
        val values = userDataFactory.mProviderMap.values
        values.forEach {
            val classObject = it.get()
            assertTrue("Key $classObject should implement LazyClassKeyable", classObject is LazyClassKeyable)
        }
    }

from dagger.

wanyingd1996 avatar wanyingd1996 commented on June 12, 2024

Hi, the r8 rule we included in the library is here. -keep the class works, but may result in your class name not being obfuscated? I still want to figure out why the class gets removed, I expect with usage of -identifiernamesstring rule, the class shouldn't have been removed. Is it ok to provide a repro of the problem? Or provide more detail about what's special about the class being removed? Also, please share the NPE stack trace. Thanks!

from dagger.

nitinsethi86 avatar nitinsethi86 commented on June 12, 2024

Please find the attached reproducer project. Do I have to add the annotation in the class being used for LazyClassKey?

Ideally I would be using the Interface to inject. However, for the sake of reproduction, I had to avoid using the interface to ensure that R8 removed it from the final APK which helps in reproducing the issue.

MultiModuleApp.zip

The stacktrace is as below:

2024-05-29 15:15:24.224 11205-11205 AndroidRuntime pid-11205 E FATAL EXCEPTION: main
Process: com.ms.multimoduleapp, PID: 11205
java.lang.RuntimeException: Unable to create application com.ms.multimoduleapp.MultiModuleApp: java.lang.IllegalArgumentException: Unknown class class G0.a
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7003)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2236)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: java.lang.IllegalArgumentException: Unknown class class G0.a
at com.ms.multimoduleapp.MultiModuleApp.onCreate(Unknown Source:110)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1316)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6998)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2236) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:205) 
at android.os.Looper.loop(Looper.java:294) 
at android.app.ActivityThread.main(ActivityThread.java:8177) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 

from dagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.