gradle-retrolambda
gradle-retrolambda copied to clipboard
Retrolambda plugin 3.3.0 doesn't strip calls to addSuppressed when using try-with-resources
lint produces a warning about this issue (and I've checked generated files as well - 3.2.5 ok, 3.3.0 broken)
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'me.tatarka:gradle-retrolambda:3.3.0'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
minSdkVersion 15
3.2.5 with retrolamda 2.3.0 works ok, too
Yes, I noticed this as well. I tried all sorts of permutations and always saw the same errors in lint, which led me to believe that the calls to those methods were actually there.
In one project I was able to just bump the minSdk to 19, because it was acceptable to do so. These calls become valid then.
@thevery do you have javaVersion JavaVersion.VERSION_1_7
in your retrolambda config by any chance?
@tbsandee that's just Lint warnings, I checked the generated code and the calls to addSuppressed are actually stripped.
@zergtmn Any idea why this happens with 3.3.0 but not 3.2.5? I guess that's the confusing thing for me.
@zergtmn no, just source/target set to 1.8. Let me re-check files again...
@tbsandee
as I can see, plugin 3.3.0 generates files to
./app/build/intermediates/transforms/retrolambda/debug/folders/1/1/retrolambda/
but 3.2.5 puts files to other folder:
./app/build/intermediates/classes/debug/
@zergtmn another confusing point is that files in ./app/build/intermediates/classes/prod/debug/
doesn't have addSuppressed
calls with 3.2.5 but does have with 3.3.0
@thevery gradle-retrolambda uses Transform API since 3.3.0 and doesn't modify the original class files produced by javac which in your case are located in ./app/build/intermediates/classes/prod/debug/
.
Do you see addSuppressed
calls in class files produced by retrolambda which are located in ./app/build/intermediates/transforms/retrolambda/debug/folders/1/1/retrolambda/
?
@zergtmn these files looks ok, let me re-check what files are analyzed by lint
Yeah, lint checks app/build/intermediates/classes
, but not app/build/intermediates/transforms
. Transform API/lint bug?
You sure lint isn't doing a source-level check here? https://github.com/evant/android-retrolambda-lombok already has instructions on how to ignore the lint check for try-with-resources pre api 19.
@evant not 100% sure about source, but transforms folder is not checked during lint task. Instructions are applied for sure - 3.2.5 works well.
Sample lint error attached:
Ah I see. They must have changed the way they detected it causing the previous filter not to work. Something like (untested)
<issue id="NewApi">
<ignore regexp="Call requires API level 19 .* java\.lang\.Throwable#addSuppressed"/>
</issue>
should work, though it's certainly odd that lint isn't looking at the transformed class files.
So proper lint.xml is the following
<issue id="NewApi">
<ignore regexp="Try-with-resources requires API level 19"/>
<ignore regexp="Call requires API level 19 \(current min is 15\): `java\.lang\.Throwable#addSuppressed`"/>
</issue>
(+default methods if used)
A more general solution that isn't tied to minSdkVersion=15:
<issue id="NewApi">
<ignore regexp="Try-with-resources requires API level 19" />
<ignore regexp="Call requires API level 19 \(current min is \d+\): `java\.lang\.Throwable#addSuppressed`" />
</issue>
Hm that's really odd. For me the original configuration from https://github.com/evant/android-retrolambda-lombok seems to be enough:
<issue id="NewApi">
<ignore regexp="Try-with-resources requires API level 19" />
</issue>
I'm also using plugin 2.2.0 and minSdkVersion 15 like @thevery.
@zergtmn I get 2 lint warnings with clean lint.xml - for both try with resources and addSuppressed. Try updating your build tools.
I need both suppressions with build tools 24.0.1.
@thevery I'm already using the latest versions of everything. Can you provide a minimal reproducible example? Edit: Ok, I was able to reproduce it on a different project.
FWIW, I tried with build tools 24.0.2 as well and still need both suppressions.
I hope I don't go too offtopic here, my build is working (right now we don't really use Lint). However, in the AndroidStudio editor it will still underline the try-with-resources red, although I did create the lint.xml file right next to my AndroidManifest.xml and also tried to specify it using
lintOptions { lintConfig file('lint.xml') }
Is there any way to get rid of the red underline in the editor?
@benj56 try placing lint.xml in the same folder as build.gradle.