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

Resolve LinkageError when more than one annotation processor references the same class. #556

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.autonomousapps.android.projects

import com.autonomousapps.AbstractProject
import com.autonomousapps.AdviceHelper
import com.autonomousapps.advice.Advice
import com.autonomousapps.advice.ComprehensiveAdvice
import com.autonomousapps.kit.*

import static com.autonomousapps.AdviceHelper.emptyCompAdviceFor
import static com.autonomousapps.AdviceHelper.compAdviceForDependencies
import static com.autonomousapps.kit.Dependency.*

final class DaggerProject extends AbstractProject {
@@ -36,7 +38,9 @@ final class DaggerProject extends AbstractProject {
bs.dependencies = [
javaxInject('api'),
dagger('api'),
daggerCompiler('kapt')
// Using two annotation processors triggers a LinkageError with a faulty `FirstClassLoader` (now resolved).
daggerCompiler('kapt'),
daggerAndroidCompiler('kapt'),
]
}
}
@@ -59,5 +63,14 @@ final class DaggerProject extends AbstractProject {
)
]

final ComprehensiveAdvice expectedAdvice = emptyCompAdviceFor(":$projectName")
private final daggerAndroid = AdviceHelper.dependency([
identifier : 'com.google.dagger:dagger-android-processor',
resolvedVersion : '2.38.1',
configurationName: 'kapt'
])

final ComprehensiveAdvice expectedAdvice = compAdviceForDependencies(
":$projectName",
[Advice.ofRemove(daggerAndroid)] as Set<Advice>
)
}
Original file line number Diff line number Diff line change
@@ -395,7 +395,7 @@ private class FirstClassLoader(
parent: ClassLoader
) : URLClassLoader(name, urls, parent) {
override fun loadClass(name: String): Class<*> = try {
findClass(name)
findLoadedClass(name) ?: findClass(name)
} catch (_: ClassNotFoundException) {
super.loadClass(name)
}
Original file line number Diff line number Diff line change
@@ -388,7 +388,7 @@ private class FirstClassLoader2(
parent: ClassLoader
) : URLClassLoader(name, urls, parent) {
override fun loadClass(name: String): Class<*> = try {
findClass(name)
findLoadedClass(name) ?: findClass(name)
} catch (_: ClassNotFoundException) {
super.loadClass(name)
}
5 changes: 5 additions & 0 deletions testkit/src/main/kotlin/com/autonomousapps/kit/Dependency.kt
Original file line number Diff line number Diff line change
@@ -143,6 +143,11 @@ class Dependency @JvmOverloads constructor(
return Dependency(configuration, "com.google.dagger:dagger-compiler:2.38.1")
}

@JvmStatic
fun daggerAndroidCompiler(configuration: String): Dependency {
return Dependency(configuration, "com.google.dagger:dagger-android-processor:2.38.1")
}

@JvmStatic
fun firebaseAnalytics(configuration: String): Dependency {
return Dependency(configuration, "com.google.firebase:firebase-analytics:17.6.0")