Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes issue 1346 #1347

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dkostyrev
Copy link

Fixes the issue #1346.

ClassReferenceParser and getBinaryAPI extension functions now handle jar files as an input alongside with class files. There is a bit of duplication with regard to to reading jar files, maybe it would be better to hide two sources of class files inside AndroidClassesTask by unpacking jars into intermediate directory. I've also added a test that fails without aforementioned fixes, it is a bit verbose because of the actual implementation of the transform task.

Copy link
Owner

@autonomousapps autonomousapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very reasonable. Thanks for the contribution! Left you a question.

Please note I think you'll have to rebase and fix some (hopefully minor) conflicts after I merge #1349.

@@ -64,6 +64,10 @@ internal fun Iterable<File>.filterToClassFiles(): List<File> {
return filter { it.extension == "class" && !it.name.endsWith("module-info.class") }
}

internal fun Iterable<File>.filterToJarFiles(): List<File> {
return filter { it.extension == "jar" && !it.name.endsWith("R.jar") }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we excluding R.jar?

Copy link
Author

@dkostyrev dkostyrev Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I've excluded R.jar because of the transitive dependencies false positives. For example, if the project uses androidx.appcompat:appcompat:1.1.0 as a dependency, the plugin would report following transitive dependencies, although none of them were really used:

These transitive dependencies should be declared directly:
  implementation 'androidx.activity:activity:1.0.0'
  implementation 'androidx.appcompat:appcompat-resources:1.1.0'
  implementation 'androidx.core:core:1.1.0'
  implementation 'androidx.customview:customview:1.0.0'
  implementation 'androidx.drawerlayout:drawerlayout:1.0.0'
  implementation 'androidx.fragment:fragment:1.1.0'
  implementation 'androidx.loader:loader:1.0.0'
  implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
  implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
  implementation 'androidx.viewpager:viewpager:1.0.0'

According to usage-dependencies.json this advice was given because of androidx.**.R classes in the R.jar:

Uses 11 classes, 5 of which are shown: androidx.core.R, androidx.core.R$attr, androidx.core.R$color, androidx.core.R$dimen, androidx.core.R$drawable

I've dug a bit deeper and find out that the plugin will add inner's class parent name to the ExplodedClass.nonAnnotationClasses and vice versa (inner class names will be added to the parent class nonAnnotationClasses), I've added a fix similar to the exclusion of the class own name in fixup functions.

Comment on lines -23 to +24
/** Will be empty for this task. */
/** May be empty. */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the comment!

@dkostyrev dkostyrev force-pushed the android-classes-jar branch from 32dfa7c to c541d6f Compare January 12, 2025 17:26
Do not ignore R.jar file.

Filter parent class name for inner class and vice versa.
@dkostyrev dkostyrev force-pushed the android-classes-jar branch from c541d6f to d52436f Compare January 12, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants