This message was deleted.
# plugin-development
s
This message was deleted.
v
Please do not split topics across several threads. This makes following the conversation in the threads view very hard as the context of the other messages is missing. If you have additional information either edit the original message or post to its thread. Regarding the problem, if it builds properly in Gradle but is shown as error in the IDE, I'd say this is an IDE bug that should be fixed in the IDE and not worked-around in your plugin.
And if you really want to and it only happens in a specific IDE, the work-around should maybe just be done during an IDE sync. In the case of IntelliJ for example you could check whether the system property
idea.sync.active
is present.
c
Ok, thx! And how to check the system property
idea.sync.active
? I'm using Android studio.
I suspect the Android plugin has a mechanism to link
R.id.xxx
in kotlin/java code to files under
/res
, but not sure. Maybe it retrofits
Android Studio
.
If I want the dependency to appear under
External Libraries
by adding the following code, how can I accomplish it?
Copy code
project.dependencies.add(appRJarConfName, project.files(
        processRes.outputs.files.find {
            it.path.endsWith("${variant.name}/R.jar")
        })
)
Like this:
The screenshot above is the effect of this code:
Copy code
dependencies {
    compileOnly fileTree(include: '**/R.jar', dir: 'build/intermediates/compile_and_runtime_not_namespaced_r_class_jar')
    // ...
}
It's ok to a variant build:
./gradlew :app:assembleGithubDebug
But error when exec
./gradlew :app:assemble
for all variants. And the error it reports is not the real reason:
Copy code
> Task :app:compileScalaGoogleplayDebugCrossScope FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':app:compileScalaGoogleplayDebugCrossScope' (type 'ScalaCompile').
  - Gradle detected a problem with the following location: '/Users/weichou/git/bdo.cash/demo-material-3/app/build/intermediates/compile_and_runtime_not_namespaced_r_class_jar/githubDebug/R.jar'.
    
    Reason: Task ':app:compileScalaGoogleplayDebugCrossScope' uses this output of task ':app:processGithubDebugResources' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':app:processGithubDebugResources' as an input of ':app:compileScalaGoogleplayDebugCrossScope'.
      2. Declare an explicit dependency on ':app:processGithubDebugResources' from ':app:compileScalaGoogleplayDebugCrossScope' using Task#dependsOn.
      3. Declare an explicit dependency on ':app:processGithubDebugResources' from ':app:compileScalaGoogleplayDebugCrossScope' using Task#mustRunAfter.
    
    For more information, please refer to <https://docs.gradle.org/8.2.1/userguide/validation_problems.html#implicit_dependency> in the Gradle documentation.
v
As I said, in my opinion you should get the IDE bug fixed instead. 😄 And I cannot tell you how to do it, I don't do any Android stuff.
And that error you just posted is a direct result of that hack-around. As the error states, you now use an output of one task within another task by configuring hard-coded paths instead of wiring task outputs to task inputs, so there is not guarantee, that the file you try to use is present or maybe even stale.
c
I know, the error it reports is not the real reason. That's why I want to make the tasks connected correctly by coding in the plugin.
v
> I know, the error it reports is not the real reason. Yes it is.
:app:processGithubDebugResources
creates this file and thus has it properly declared as output. By adding this file to
compileOnly
you make
:app:compileScalaGoogleplayDebugCrossScope
use the file as input. But those two tasks do not have a dependency as the error says.
That's why I want to make the tasks connected correctly by coding in the plugin.
As I said, I have near to no knowledge about Android. The problem probably is, that you declare the R.jar of one variant as dependency for all variants and thus those tasks are no connected. If you would only do it during IDE sync, this problem should not exist I'd say.
c
So how can I complete this?
Copy code
project.dependencies.add(appRJarConfName, project.files(
        processRes.outputs.files.find {
            it.path.endsWith("${variant.name}/R.jar")
        })
)
appRJarConfName
separates the variants. But only this code is not working. I mean I want the dependency to appear under
External Libraries
.
It's not about how much Android you know.
v
It is, because I have no idea how the whole Android variant thing works.
c
Haha, ok! Thank you for your valuable analysis.
👌 1
Also, I would like to know what is the mechanism behind
compileOnly
(if there are other mechanisms bundled with IDE).
v
What do you mean with "mechanism"? It is a configuration. And
compileClasspath
configuration extends from it, but
runtimeClasspath
does not. By that it is part of the compile classpath but not of the runtime classpath.
c
I know it's a
org.gradle.api.artifacts.Configuration
, i need to know more.
If you can't solve my problem, you don't need to answer. Wait for someone who knows more to come.
v
I know pretty much, it is just that it is unclear to me what you want to know 🙂
Sorry, I cannot huddle
c
I solved the problem:
Copy code
project.dependencies.add("${variant.name}CompileOnly", project.files(
        processRes.outputs.files.find {
            it.path.endsWith("${variant.name}/R.jar")
        })
)
So i guess there must be some mechanism behind
compileOnly
(just change
appRJarConfName
to
"${variant.name}CompileOnly"
and it works fine).