paparazzi icon indicating copy to clipboard operation
paparazzi copied to clipboard

Javac warning "class file for android.compat.annotation.UnsupportedAppUsage not found"

Open TWiStErRob opened this issue 3 years ago • 2 comments

Recently I added this to my project:

tasks.withType<JavaCompile> {
	options.compilerArgs = options.compilerArgs + listOf(
		// Enable all warnings during compilation.
		"-Xlint:all",
		// Fail build when warnings pop up.
		"-Werror",
	)
}

after, I started getting this issue:

> Task :component:widget:compileDebugUnitTestJavaWithJavac FAILED
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage': class file for android.compat.annotation.UnsupportedAppUsage not found
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/View.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/content/Context.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/content/Context.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/content/Context.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/LayoutInflater.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/LayoutInflater.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/LayoutInflater.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/LayoutInflater.class): warning: Cannot find annotation method 'maxTargetSdk()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/LayoutInflater.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
P:\caches\gradle\caches\modules-2\files-2.1\app.cash.paparazzi\layoutlib-native-jdk11\2020.3.1-852189b\13849f7f0cd4d9afb62bc5b912e41536cf6f49d3\layoutlib-native-jdk11-2020.3.1-852189b.jar(/android/view/LayoutInflater.class): warning: Cannot find annotation method 'trackingBug()' in type 'UnsupportedAppUsage'
error: warnings found and -Werror specified
1 error
44 warnings

I tried reproducing it inside :sample, but couldn't. I suspected compileSdkVersion, androidx, or transitive dependency on paparazzi, but no luck.

The only repro I have is:

  • Clone https://github.com/TWiStErRob/net.twisterrob.sun/tree/v1.1.0
  • Check out v1.1.0
  • Add this into commonAndroidConfig.kt > fun commonAndroidConfig:
    	tasks.withType<org.gradle.api.tasks.compile.JavaCompile> {
    		options.compilerArgs = options.compilerArgs + listOf(
    			// Enable all warnings during compilation.
    			"-Xlint:all",
    			// Fail build when warnings pop up.
    			"-Werror",
    		)
    	}
    
  • Run gradlew :component:widget:clean :component:widget:compileDebugUnitTestJavaWithJavac --no-build-cache

I understand I might be doing something weird with the build plugins, just wanted to start a conversation in case you have seen this before somewhere.

In Android Studio when I try to navigate to UnsupportedAppUsage it doesn't see it either, and in paparazzi project I see UnsupportedAppUsage.java inside Platform 29.

TWiStErRob avatar Jan 22 '22 12:01 TWiStErRob

After some guessing and running javac -X, I managed to work around it by adding

// Workaround for https://github.com/cashapp/paparazzi/issues/362.
"-Xlint:-classfile",

but obviously this just hides the problem (and potentially others too).

TWiStErRob avatar Jan 22 '22 13:01 TWiStErRob

just wanted to start a conversation in case you have seen this before somewhere

definitely haven't seen this before. will try to dig in next week.

jrodbx avatar Jan 22 '22 18:01 jrodbx

Spent a little time looking into this, and I have no good solutions for this, so moving to the Backlog in case someone else contributes a solution. Maybe working around the problem by only configuring the main source set's JavaCompile task, instead of all the JavaCompile tasks will help?

jrodbx avatar Apr 23 '23 04:04 jrodbx

instead of all the JavaCompile tasks will help?

Yeah, that works as a more specific workaround, it it's still a workaround. I would want to know all the classfile problems, even in test source set.

Spent a little time looking into this

Apart from no solution, did you manage to figure out some kind of understanding why/where/what is causing this?

TWiStErRob avatar Apr 24 '23 17:04 TWiStErRob

did you manage to figure out some kind of understanding why/where/what is causing this?

I think:

  • layoutlib doesn't package the annotation (android.compat.annotation.UnsupportedAppUsage) in its prebuilt artifact
  • the annotation isn't bundled in another public artifact (in order to be added as a Paparazzi gradle dependency)
  • we'd have to shadow/relocate another AOSP prebuilt to include that annotation

jrodbx avatar Apr 24 '23 21:04 jrodbx

Closing as wontfix

jrodbx avatar Jun 14 '23 07:06 jrodbx