Comments (7)
Thanks, I was able to repro, and found that there is something changed between agp 8.3.0 and 8.4.0, causing the resulting obfuscated code to change.
with 8.3.0:
The identifier name string rule is working properly, with the map key obfuscated.
Our identifier name string rule fails to take effect with 8.4.0, and the name of the class ILogger was not obfuscated, therefore causing the inconsistency when trying to read the map passing in the obfuscated class name.
As you mentioned in an earlier comment:
I use the R8 version 8.2.47 that ships with AGP 8.2.2.
I tried changing classpath 'com.android.tools.build:gradle:8.4.0'
to classpath 'com.android.tools.build:gradle:8.2.2'
, this runs successfully, so I'm not sure where does the error coming from for that one.
In summary, the problem is our identifier name string rules fails to take effect in the newest AGP. In this case, you may add the following rule:
-keepclasseswithmembers,includedescriptorclasses class * {
@dagger.internal.KeepFieldType <fields>;
}
to your proguard.pro, this will keep all @LazyClassKey referenced class names, so that you won't need to mark them individually.
At the meantime, I will try to figure out why the rule fails to take effect, and probably follow up with AGP team about the issue. Thanks!
from dagger.
Hi, AGP team has fixed the issue in in R8 version 8.4.37 and 8.5.23, so the alternative solution is override the r8 version in settings.gradle.
pluginManagement {
buildscript {
repositories {
mavenCentral()
maven {
url = uri("https://storage.googleapis.com/r8-releases/raw")
}
}
dependencies {
classpath("com.android.tools:r8: 8.4.37")
}
}
}
from dagger.
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.
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.
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.
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.
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.
Thanks @wanyingd1996. This seems to be working. I will test it more and update here.
from dagger.
Related Issues (20)
- Subcomponent MembersInjector error in 2.51 HOT 1
- Does Hilt always execute app module during instrumented test? HOT 3
- [KSP] Dagger-KSP does not see typealiased dagger annotations HOT 3
- Cannot invoke getAnnotationValue because "annotation" is null HOT 14
- Creator-less subcomponents are not visible to modules HOT 1
- Suggestion to add isInit() api to dagger.Lazy HOT 1
- [Error] : java.lang.ClassNotFoundException: Didn't find class "com.myproject.MainApplication" on path: DexPathList HOT 1
- K2 KAPT (aka KAPT4) doesn't like inline/reified. HOT 3
- [KSP2] ClassCastException: class KSClassDeclarationEnumEntryImpl cannot be cast to class XEnumEntry HOT 2
- Hilt: Injection not working in BroadcastReceiver HOT 4
- Assisted injection appears to not work correctly in some cases HOT 3
- [Dagger/MissingBinding] com.xxx.onboarding.presentation.otp.LoginViewModel cannot be provided without an @Inject constructor or an @Provides-annotated method. public abstract static class SingletonC implements SemaaiApplication_GeneratedInjector HOT 1
- Hilt Class Generation Fails After Upgrading to AGP 8.5.1 from 8.0.1 HOT 6
- Issue with Dagger Hilt Upgrade from 2.48 to 2.49 - Unable to Load Class JavacBasicAnnotationProcessor HOT 1
- Way to replace a dependency created using Constructor Injection for all tests using Hilt. HOT 4
- After updating from 2.51.1 to 2.52, my GWT application does not compile HOT 14
- NPE On Lazy Dagger
- [KSP] Component processing is not deferred if there are unresolved symbols in the current round HOT 3
- [KAPT] - Issue build type release AGP 8.4.0 - 8.5.2 Kotlin 1.9.24 and Dagger 2.52
- SomeClass$LazyClassKeyProviders.class generated by Dagger/Hilt is not deterministic
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dagger.