Status Update
Comments
sb...@google.com <sb...@google.com>
al...@google.com <al...@google.com> #2
Lint options:
lintOptions {
lintConfig = file('lint.xml')
abortOnError true
xmlReport true
htmlReport true
checkDependencies true
}
Also, our project has custom lint rules. Failure happens with a dependency of 26.6.3 and 27.0.0.
Is any way to downgrade lint runner? This problem is keeping us from using AGP 4.0
le...@gmail.com <le...@gmail.com> #3
Attached slightly different stacktrace for the same problem.
Wonder if disabling some lint rules could help to "fix" this problem, as it is also blocking for us 4.0 AGP upgrade.
vs...@google.com <vs...@google.com>
g....@gmail.com <g....@gmail.com> #4
Notes:
I suspect the exceptions are happening now because JetBrains recently changed an assert
statement into a hard failure (see
I.e., it's possible that Lint has been hitting this code path all along, and only now it is causing a problem.
This has been difficult to investigate so far because the failure is nondeterministic and also deep inside the Kotlin compiler. Plus, JetBrains seems to be hitting this code path occasionally too (hence why they changed the assert into a hard failure), so I'm not even sure whether Lint is implicated or not.
vs...@google.com <vs...@google.com> #5
It could also explain why not all lint rules were working from time to time (
Is any public issue created I could follow?
vs...@google.com <vs...@google.com> #6
Has anyone tried this with 4.1.0-beta2? We're using a more recent version of UAST and the Kotlin compiler there. It's not clear that it's fixed but -- there's a chance :-)
ju...@gmail.com <ju...@gmail.com> #7
I tried. The same error. I am wondering, is any way to know which lint checks cause failure? I have a few custom lint checks. Or, is any way downgrade compiler for lint checks?
vs...@google.com <vs...@google.com> #8
I did more tests and probably narrow down a cause. I did all tests on 4.1.0-beta2
. Original configuration have enabled checkDependencies
and included custom lint checks. Custom lint checks are compiled using 26.6.3
version:
checkDependencies = true, customLintChecks = true
= 20% chance of successcheckDependencies = true, customLintChecks = false
= 57% chance of successcheckDependencies = false, customLintChecks = true
= 100% chance of success
It is a clear evidence that checkDependencies
feature is not stable. In addition, custom lint checks is not friendly with checkDependencies
and increases the risk of failure. Or maybe just an old lint SDK used is to blame.
It is very similar to
I have a theory, but do not know how to test. Maybe crashes happening because there are some lint checks from libs built upon old lint SDK version?
[Deleted User] <[Deleted User]> #9
To me this is happening on 4.2.0-alpha04 too.
Can someone confirm that this is happening if you have these three conditions met?:
- checkDependencies=true on your app module
- have a custom lint rule using lintChecks on your app module
- have a custom lint rule using lintChecks on your library module
For me the error went away after I removed the lintChecks on the library module.
ra...@journeyapps.com <ra...@journeyapps.com> #11
As opposed to lintPublish
? Or is that not relevant?
al...@google.com <al...@google.com> #12
For me this is for local checks so I'm using lintChecks. Removing lintChecks from the library module and only applying it on the app module fixed the lint crash. However that's not optimal as I want to run the lint checks individually on the library module as well. It would not be interesting if this is really the cause of the issue or if it doesn't fix it for others.
vs...@google.com <vs...@google.com> #13
I do not have any custom lint checks declared but there might be a transient lint check pulled in.
ai...@gmail.com <ai...@gmail.com> #14
We have checkDependencies=true
on our app module and apply there custom lint checks. Disabling custom lint checks has not solved the issue, though we have more custom lint checks via external dependencies (for example, timber).
[Deleted User] <[Deleted User]> #15
#14, could you check with checkDependencies=false
? It fixes problem on my project. Would be nice to hear more proves.
vi...@gmail.com <vi...@gmail.com> #17
In my case, all builds of the >50 were a success after checkDependencies = false
. However, disabling checkDependencies
is not a solution as well. Since all our code is split in small logical modules, there is no point in lint. Too many false-positives and true-negatives.
ta...@gmail.com <ta...@gmail.com> #18
I cherry-picked a change to 4.1 Beta 4 which essentially changes this error into a logged warning rather than a hard failure. That does not "fix" the problem, but it at least gets us back to the behavior of 3.6. Can someone confirm that this workaround has worked for them?
Also, I think I know what the root cause is (see notes below). However, it's hard to be sure without a repro scenario. Would anyone be willing to share an open-source project that reproduces this bug? (You can also send the project to
Notes:
-
My current theory is that this bug is related to
.https://issuetracker.google.com/159733104#comment6
I.e., I think Lint should not be reusing the same Kotlin compiler environment to analyze multiple modules, which is what we do whencheckDependencies=true
. -
It is still strange that the failure is nondeterministic. However, one potential reason is that the Kotlin compiler caches many things via
SoftReference
.
av...@gmail.com <av...@gmail.com> #19
Sorry for my long delay. I was tried with 4.1.0-beta05
(newest version to date), and the problem is still here. I added new log in case lines were changed.
Would anyone be willing to share an open-source project that reproduces this bug?
I have only closed source project with this problem. Maybe someone knows some quite large multimodule opensource project I could try setup AGP with lint and try reproduction?
lu...@gmail.com <lu...@gmail.com> #20
I tried to reproduce with two small multimodule projects, but all builds works flawlessly. Also, I tried to reproduce using checkDependencies
, and 6 other helper modules. 145k CLOC without tests. I suppose there is a good chance problem happen due to the cache.
It is still strange that the failure is nondeterministic.
It is even non-deterministic in CI/docker builds using the same fresh environment and exactly the same code each time. Build cache and daemon is disabled there. Multithreading should be involved as well.
In addition, I found in most cases failed due to the same file
da...@gmail.com <da...@gmail.com> #21
vs...@google.com <vs...@google.com> #22
There are some architectural changes coming in Lint that will fix this properly, but they will not make it into 4.2.
However, there is another workaround you can try that will be available starting in AGP 4.2 Beta 4.
Essentially you can tell Lint to "reset" the Kotlin compiler between each module analysis, thereby clearing all caches. I did not make this the default behavior because the effect on performance is unknown/risky.
To enable this behavior, either set the environment variable LINT_DO_NOT_REUSE_UAST_ENV
to "true", or set the JVM system property lint.do.not.reuse.uast.env
to "true". For example, you can do this from the command line:
./gradlew -Dlint.do.not.reuse.uast.env=true :app:lintDebug
Or by putting this in your gradle.properties
file:
systemProp.lint.do.not.reuse.uast.env=true
ra...@journeyapps.com <ra...@journeyapps.com> #23
Status updates:
-
I'm still hoping someone can confirm whether the workaround in
worked for them in AGP 4.2.comment#22 -
Starting with AGP 7.0-alpha13 the root cause of this issue should be fixed completely due to the new "partial analysis" mode (enabled by default) in which Lint analyzes modules independently and merges results along the way. It fixes the issue because Lint will no longer use the same Kotlin compiler environment to analyze multiple modules (and so the risk of stale caches is gone).
[Deleted User] <[Deleted User]> #24
I'm still hoping someone can confirm whether the workaround in
worked for them in AGP 4.2. comment#22
This unfortunately did not work for us. We actually see lint crashes after enabling via systemProp.lint.do.not.reuse.uast.env=true
. See the attached log. It's also much slower, as expected.
AGP 4.2 seems to make this error much more frequent compared to 4.1, for some reason.
da...@gmail.com <da...@gmail.com> #25
Can you file a new bug? You can add a comment here linking to it.
ne...@gmail.com <ne...@gmail.com> #26
Sure. Without that workaround, we get the same
ERROR: package fragment is not found for module:<lint-module> is a module[ModuleDescriptorImpl@5e5e6c61] file:KtFile: LiveViewerViewData.kt
error in this ticket occasionally (1-2% of the time?).
ne...@gmail.com <ne...@gmail.com> #27
Oh, I misunderstood. So, using lint.do.not.reuse.uast.env
is what causes the new crash? That is unfortunate, and I will investigate. Let me know if there is a sample project you can share that reproduces the issue.
ne...@gmail.com <ne...@gmail.com> #28
Not sure if you still wanted the new bug, but here it is:
ne...@gmail.com <ne...@gmail.com> #29
FYI the issue in
And to confirm, lint.do.not.reuse.uast.env
should no longer be needed at all in AGP 7.0+.
cl...@gmail.com <cl...@gmail.com> #30
Thanks #29 . I am noticing that when this happens, after the error log for
package fragment is not found for module:<lintWithKotlin> is a module
There is another error
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'descriptor' of org/jetbrains/kotlin/codegen/context/CodegenContext.intoPackagePart must not be null
at org.jetbrains.kotlin.codegen.context.CodegenContext.$$$reportNull$$$0(CodegenContext.java)
at org.jetbrains.kotlin.codegen.context.CodegenContext.intoPackagePart(CodegenContext.java)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject$computeLightClassData$1$1.invoke(LightClassDataProvider.kt:51)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject$computeLightClassData$1$1.invoke(LightClassDataProvider.kt:38)
at org.jetbrains.kotlin.asJava.builder.LightClassBuilderKt.buildLightClass(LightClassBuilder.kt:64)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject$computeLightClassData$1.invoke(LightClassDataProvider.kt:47)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject$computeLightClassData$1.invoke(LightClassDataProvider.kt:38)
at org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport.createDataHolderForClass(CliLightClassGenerationSupport.kt:64)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject.computeLightClassData(LightClassDataProvider.kt:45)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject.compute(LightClassDataProvider.kt:61)
at com.intellij.psi.impl.PsiCachedValueImpl.doCompute(PsiCachedValueImpl.java:54)
at com.intellij.util.CachedValueBase.lambda$getValueWithLock$1(CachedValueBase.java:235)
at com.intellij.openapi.util.RecursionManager$1.doPreventingRecursion(RecursionManager.java:113)
at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:72)
at com.intellij.util.CachedValueBase.getValueWithLock(CachedValueBase.java:236)
at com.intellij.psi.impl.PsiCachedValueImpl.getValue(PsiCachedValueImpl.java:43)
at
Does the fix address both of these?
lu...@gmail.com <lu...@gmail.com> #31
package fragment is not found
and Argument for @NotNull parameter...
), the workaround in 4.2 is to put
systemProp.lint.do.not.reuse.uast.env=true
in your gradle.properties
file as described in
ss...@gmail.com <ss...@gmail.com> #32
Marking fixed in AGP 7.0.
That is, the lint.do.not.reuse.uast.env
workaround should no longer be needed in AGP 7.0+. And, you should no longer see the following warnings/errors while running Lint:
ERROR: package fragment is not found for module:<lintWithKotlin>...
ERROR: Could not generate LightClass for...
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'descriptor' of org/jetbrains/kotlin/codegen/context/CodegenContext.intoPackagePart must not be null
The issue is fixed due to the new "Lint partial analysis" mode (enabled by default) which creates a standalone UastEnvironment
instance for each module, thereby avoiding stale caches in the Kotlin compiler frontend.
Please comment on the bug if you see any similar errors in AGP 7.0+.
lu...@gmail.com <lu...@gmail.com> #33
sa...@gmail.com <sa...@gmail.com> #35
cl...@gmail.com <cl...@gmail.com> #36
lu...@gmail.com <lu...@gmail.com> #37
In jar project in JUnit tests I cant get resource from production code (jar_module/src/main/resources/**)
When I run test from gradle its fine. But when I run JUnit production resources from jar project are invisible. This will be fixed in 1.2?
go...@contact.mpierce.org <go...@contact.mpierce.org> #38
dl...@gmail.com <dl...@gmail.com> #39
1. Add the copyTestResources task to your build.gradle from answer #26, but without dependsOn line.
2. Open Studio Run Configurations / Defaults / JUnit|TestNG.
3. Add 'Before launch' task / Gradle / copyTestResources (leave 'Gradle project' empty for multi-project).
Now Android Studio will automatically run the copyTestResources task whenever you launch the test from it.
ku...@gmail.com <ku...@gmail.com> #40
afterEvaluate {
/* Include resources. See:
project.android.productFlavors.each { f ->
project.android.buildTypes.each { b ->
/** compose dynamic tasks */
def tName = "copy${f.name.capitalize()}${b.name.capitalize()}TestResources"
project.task(tName, type: Copy) {
description = "Make resources available for test: test${f.name.capitalize()}${b.name.capitalize()}."
group = 'Unit Testing'
from project.android.sourceSets["test"].resources.srcDirs
into "${project.buildDir}/intermediates/classes/test/${
}
tasks.matching { it.name.equalsIgnoreCase("test${
it.dependsOn tName
}
}
}
}
mr...@gmail.com <mr...@gmail.com> #41
jt...@gmail.com <jt...@gmail.com> #43
Grab this file and put it in your app module:
Update the build.gradle file in the module to apply the workaround:
apply from: 'build.workaround-missing-resource.gradle'
Thats it! Resources should now be loaded when running tests from within Android Studio.
Obviously if you've been hacking about with various fixes above then just remember to restore your build.gradle files above first to a clean state and remove any modifications made to junit run configurations.
Assuming you are loading a file called testdata.json located in src/test/resources then any of the following will resolve the file:
ClassLoader.getSystemResourceAsStream("testdata.json")
getClass().getClassLoader().getResourceAsStream("testdata.json")
getClass().getResourceAsStream("/testdata.json")
Full credit to Nico Küchler for this elegant fix; it just about saved me from going completely insane!
am...@gmail.com <am...@gmail.com> #44
One caveat for me though, is that I am testing a module which is a library project, so the build variants must use libraryVariants not applicationVariants in
build.workaround-missing-resource.gradle
// Copy must be done for each variant.
def variants = android.libraryVariants.collect()
Put test resources in src/test/resources and fetch them just using the filename and it works!
th...@gmail.com <th...@gmail.com> #45
I build a project the demonstrate the problem and have a proposed solution:
It contains a piece of gradle script to copy the java resources within the dependent AARs/JARs to test classes directory.
gradle.projectsEvaluated {
// Base path which is recognized by android studio.
def testClassesPath = "${buildDir}/intermediates/classes/test/"
// Copy must be done for each variant.
def variants = android.applicationVariants.collect()
variants.each { variant ->
def variationName = variant.name.capitalize()
// Get the flavor and also merge flavor groups.
def productFlavorNames = variant.productFlavors.collect { it.name.capitalize() }
if (productFlavorNames.isEmpty()) {
productFlavorNames = [""]
}
productFlavorNames = productFlavorNames.join('')
// Base path addition for this specific variant.
def variationPath =
if (productFlavorNames != null && !productFlavorNames.isEmpty()) {
variationPath = uncapitalize(productFlavorNames) + "/${variationPath}"
}
configurations.compile.each {
String p = it.absolutePath
if (p.endsWith('.jar')) {
copy {
from zipTree(p)
into file("${testClassesPath}/${variationPath}")
exclude '**/*.class'
}
}
else if (it.absolutePath.endsWith('.aar')) {
FileTree t = zipTree(it.absolutePath)
t.each {
String p2 = it.absolutePath
if (p2.endsWith('jar')) {
copy {
from zipTree(p2)
into file("${testClassesPath}/${variationPath}")
exclude '**/*.class'
}
}
}
}
}
copy {
from project.android.sourceSets["test"].resources.srcDirs
into "${project.buildDir}/intermediates/classes/test/${variationPath}"
}
}
}
an...@gmail.com <an...@gmail.com> #46
Following "convention over configuration" we should be able to just place those files in src/test/resources and have them available to our unit tests, without requiring extra configuration.
Is there any update on this bug? Are there plans to resolve it?
jl...@j3ltd.com <jl...@j3ltd.com> #47
The description of 75991 is vague enough to be classified as ongoing and never going to be resolved.
So my understanding is no there are no plans to resolve the issue on this page (64887).
Maybe someone at Google has a better insight into the issue processing process?
or...@gmail.com <or...@gmail.com> #48
or...@gmail.com <or...@gmail.com> #49
OS version: OSX 10.11.1
Java JRE/JDK version: jdk1.7.0_79
I'm using a java module inside android app structure. Above issue still occurs in the module. Resources not are copied into classes/tests, thus I use the workaround which is provided.
[Deleted User] <[Deleted User]> #50
go...@gmail.com <go...@gmail.com> #51
task copyTestResources(type: Copy) {
from "${projectDir}/src/test/resources"
into "${buildDir}/classes/test"
}
processTestResources.dependsOn copyTestResources
task copyMainResources(type: Copy) {
from "${projectDir}/src/main/resources"
into "${buildDir}/classes/main"
}
copyTestResources.dependsOn copyMainResources
Hope this is fixed soon...
jo...@squins.com <jo...@squins.com> #52
dependencies {
...
runtime files('build/resources/main')
// Not tested.
testRuntime files('build/resources/test')
...
}
pa...@gmail.com <pa...@gmail.com> #53
task copyTestResources(type: Copy) {
from "${projectDir}/src/test/resources"
into "${buildDir}/classes/test"
}
processTestResources.dependsOn copyTestResources
task copyMainResources(type: Copy) {
from "${projectDir}/src/main/resources"
into "${buildDir}/classes/main"
}
copyTestResources.dependsOn copyMainResources
Hope this is fixed soon... "
I can also confirm this as still an issue in 2.2
Thank you Goncalos, I spent so long trying to work out why the classloader wasn't picking up my resources (main not test). On the plus side you could say I know a bit more about classloader now.
mh...@gmail.com <mh...@gmail.com> #54
إغلاق وازالة هذا التتطبيق
am...@gmail.com <am...@gmail.com> #55
37605 -Dfile.encoding=UTF-8 -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -Djna.nosys=true ...
Description
OS version: 10.9.1
Java JRE/JDK version: jdk1.7.0_25
When running JUnit tests from Android Studio (for non-Android code) it doesn't automatically add the test resources directory to the classpath. Running "gradle test" via commandline produces the same result, but I can add the following lines to get it working (though this seems like a hacky workaround):
test {
setClasspath(sourceSets.test.runtimeClasspath)
}
This doesn't fix it in Android Studio though, so I can't find any workaround except to use explicit hard coded paths (bleargh) rather than "Class.getResource".