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, 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.
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.
Related Issues (20)
- error when ksp.useKSP2=true HOT 2
- Suppress annotation on @Inject is not honored on the Factory HOT 1
- [KSP2] Dagger and Hilt incompatibility with KSP2 HOT 4
- [KSP2] NullPointerException: null cannot be cast to non-null type androidx.room.compiler.processing.XType HOT 1
- OutOfMemoryError with Maven HOT 1
- DaggerAppComponent not creating in the version 2.51.1 HOT 3
- java.lang.ClassNotFoundException: dagger.spi.shaded.androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor. Hilt 2.49+ HOT 1
- how to manually generate module HOT 1
- Explain how to add dagger jar files manually to the android project HOT 2
- Annotate interface with default Bind implementation HOT 2
- Transitive vulnerability from symbol-processing-api HOT 1
- java.lang.IllegalArgumentException: CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY` HOT 4
- Update of different dependency: Error "package javax.annotation.processing is not visible" HOT 4
- Compile time error with KSP with Generics HOT 4
- java.lang.IllegalArgumentException: Multiple entries with same key HOT 4
- Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction > java.lang.reflect.InvocationTargetException (no error message) HOT 2
- Stackoverflow when exposing parents of Subcomponents HOT 7
- Hilt not working with android testFixtures? HOT 2
- Hilt 2.44.2 - Class not found when use @AndroidEntryPoint at WidgetReceiver HOT 1
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.