王欢
08/09/2024, 4:01 AMFailed to notify project evaluation listener.> java.lang.IllegalStateException: Cannot change attributes of configuration 'appreleaseUnitTestCompileClasspath' after it has been locked for mutation > KotlinJvmAndroidCompilation with name 'releaseUnitTest' not found.
class PluginMain:Plugin<Project> {
override fun apply(target: Project) {
soSearch(project = target)
}
private fun soSearch(project: Project){
val appExtension = project.extensions.getByType(AppExtension::class.java)
appExtension.applicationVariants.all{
val applicationVariants = this.name
System.err.println("applicationVariants $applicationVariants")
val configuration = project.configurations.getByName(applicationVariants + "CompileClasspath")
println("SoPlugin applicationVariants $applicationVariants")
configuration.forEach { file ->
println("SoPlugin" + "file " + file.name)
val fineName = file.name
if (fineName.endsWith(".jar") || fineName.endsWith(".aar")) {
try {
val jarFile = JarFile(file)
val enums: Enumeration<*> = jarFile.entries()
while (enums.hasMoreElements()) {
val jarEntry: JarEntry = enums.nextElement() as JarEntry
if (jarEntry.name.endsWith(".so")) {
println("SoPlugin" + "----soEntry " + jarEntry.name)
}
}
} catch (e: IOException) {
// throw RuntimeException(e)
}
}
}
}
}
}Vampire
08/09/2024, 6:49 AM王欢
08/09/2024, 7:21 AMtarget.afterEvaluate {
soSearch(this)
}Vampire
08/09/2024, 7:30 AMafterEvaluate is to introduce timing problems, ordering problems, and race conditions. It is like using SwingUtilities.invokeLater or Platform.runLater to "fix" a GUI problem. It just does symptom treatment, delaying the problem to a later, harder to reproduce, harder to debug, and harder to fix point in time.王欢
08/09/2024, 8:12 AMVampire
08/09/2024, 8:41 AM王欢
08/09/2024, 8:47 AM王欢
08/09/2024, 8:47 AMVampire
08/09/2024, 8:48 AMVampire
08/09/2024, 8:48 AMVampire
08/09/2024, 8:49 AM王欢
08/09/2024, 8:51 AMVampire
08/09/2024, 8:52 AMafterEvaluate the error is not solved, just made more fragileVampire
08/09/2024, 8:53 AMprintln statements?
Why do they need to be done at configuration time?王欢
08/09/2024, 8:53 AMVampire
08/09/2024, 8:54 AM王欢
08/09/2024, 8:54 AM王欢
08/09/2024, 8:54 AMVampire
08/09/2024, 8:56 AMVampire
08/09/2024, 8:56 AM王欢
08/09/2024, 8:57 AMVampire
08/09/2024, 9:00 AMafterEvaluate is not after configuration it is still during configuration, and there can still things be done later that make it fail again, you just make your code less reliable, more buggy, more flaky, and more bad-practice.Vampire
08/09/2024, 9:00 AM王欢
08/09/2024, 9:04 AMFailed to notify project evaluation listener.> java.lang.IllegalStateException: Cannot change attributes of configuration 'appreleaseUnitTestCompileClasspath' after it has been locked for mutation > KotlinJvmAndroidCompilation with name 'releaseUnitTest' not found. this question ?
Vampire
08/09/2024, 9:04 AM王欢
08/09/2024, 9:05 AMVampire
08/09/2024, 9:05 AMVampire
08/09/2024, 9:05 AMVampire
08/09/2024, 9:06 AM王欢
08/09/2024, 9:07 AMVampire
08/09/2024, 9:08 AM王欢
08/09/2024, 9:09 AMVampire
08/09/2024, 9:12 AMConfiguration is an Iterable<File>.
When you call forEach on it, you resolve the configuration as it is configured at that point in time and iterate over the files.
This means you miss any changes done after that, or if you are "lucky" the build fails if changes are attempted after that.
So you should usually not do this at configuration time, but for example in the execution phase of some task.Vampire
08/09/2024, 9:13 AMafterEvaluate, then in 98.7% of the cases it is the wrong thing to do王欢
08/09/2024, 9:15 AMVampire
08/09/2024, 9:15 AM王欢
08/09/2024, 9:19 AM王欢
08/09/2024, 9:21 AMVampire
08/09/2024, 9:22 AMafterEvaluate is pratically never a fix and almost never appropriate.
> afterEvaluate received atfer all configure done
No, it does not.
If I apply your plugin and then do something in an afterEvaluate or apply another plugin that also uses afterEvaluate that will run after your afterEvaluate as they are run in registration order and they are still part of the configuration phase.Vampire
08/09/2024, 9:24 AM王欢
08/09/2024, 9:24 AM