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

PMD error on Android projects using Play Services or LeakCanary #37

Closed
barriosnahuel opened this issue Apr 19, 2020 · 2 comments
Closed

Comments

@barriosnahuel
Copy link
Contributor

barriosnahuel commented Apr 19, 2020

Hi!

I'm having two issues after upgrading to SCA v3.0.0.

First one is related to PMD, second one to Spotbugs.

Context

I was using v2.6.12 fine in the given context:

  • PMD enabled
  • Gradle v5.6.4
  • Android project
    • 'com.android.tools.build:gradle:3.6.2'
    • App module, 1 dynamic feature module, many library modules (all in the same repository)

Note: SCA v2.6.12 comes with PMD v6.20.0

Error

PMD runs ok in all modules but on the dynamic feature module, I'm getting the following result:

* What went wrong:
Execution failed for task ':my_anroid_dynamic_feature_module:processDebugAndroidTestResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:34:13-36:66: AAPT: error: resource xml/leak_canary_file_paths (aka com.github.myawesomeproject.awesomefeature.test:xml/leak_canary_file_paths) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:39:9-44:66: AAPT: error: resource mipmap/leak_canary_icon (aka com.github.myawesomeproject.awesomefeature.test:mipmap/leak_canary_icon) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:39:9-44:66: AAPT: error: resource string/leak_canary_display_activity_label (aka com.github.myawesomeproject.awesomefeature.test:string/leak_canary_display_activity_label) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:39:9-44:66: AAPT: error: resource style/leak_canary_LeakCanary.Base (aka com.github.myawesomeproject.awesomefeature.test:style/leak_canary_LeakCanary.Base) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:46:9-62:26: AAPT: error: resource drawable/leak_canary_tv_icon (aka com.github.myawesomeproject.awesomefeature.test:drawable/leak_canary_tv_icon) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:46:9-62:26: AAPT: error: resource bool/leak_canary_add_launcher_icon (aka com.github.myawesomeproject.awesomefeature.test:bool/leak_canary_add_launcher_icon) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:46:9-62:26: AAPT: error: resource mipmap/leak_canary_icon (aka com.github.myawesomeproject.awesomefeature.test:mipmap/leak_canary_icon) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:46:9-62:26: AAPT: error: resource string/leak_canary_display_activity_label (aka com.github.myawesomeproject.awesomefeature.test:string/leak_canary_display_activity_label) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:46:9-62:26: AAPT: error: resource style/leak_canary_LeakCanary.Base (aka com.github.myawesomeproject.awesomefeature.test:style/leak_canary_LeakCanary.Base) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:64:9-70:68: AAPT: error: resource mipmap/leak_canary_icon (aka com.github.myawesomeproject.awesomefeature.test:mipmap/leak_canary_icon) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:64:9-70:68: AAPT: error: resource string/leak_canary_storage_permission_activity_label (aka com.github.myawesomeproject.awesomefeature.test:string/leak_canary_storage_permission_activity_label) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/12544b80cee21462a629a686340edfa2/jetified-leakcanary-android-core-2.2/AndroidManifest.xml:64:9-70:68: AAPT: error: resource style/leak_canary_Theme.Transparent (aka com.github.myawesomeproject.awesomefeature.test:style/leak_canary_Theme.Transparent) not found.
         
     /Users/myuser/.gradle/caches/transforms-2/files-2.1/1242a38a4d8d07b0c228c34712765379/jetified-play-services-basement-17.0.0/AndroidManifest.xml:23:9-25:69: AAPT: error: resource integer/google_play_services_version (aka com.github.myawesomeproject.awesomefeature.test:integer/google_play_services_version) not found.
         

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 6s
82 actionable tasks: 14 executed, 68 up-to-date

What I've tried

  • Bump 'com.android.tools.build:gradle:3.6.2' to v3.6.3 ==> same error
  • Bump Gradle to v6.3 ==> same error
  • Build a local version of SCA v3.0.0 downgrading to PMD v6.20.0 ==> same error
  • Remove dependency LeakCanary and its usages ==> same error (only for Play Services)
  • Clone project again ==> same error
  • Downgrade Gradle to v5.2.1 (with 'com.android.tools.build:gradle:3.4.1') ==> It works! 🤔

Why I tried downgrading to v5.2.1?
After upgrading to SCA v3.0.0, when running:

./gradlew spotbugs

I'm getting the following error:

No classes configured for SpotBugs analysis.

which is extremely similar to spotbugs/spotbugs-gradle-plugin#23.

But in this new context with Gradle v5.2.1 when running spotbugs I fall into spotbugs/spotbugs-gradle-plugin#90.

Since all was working ok before upgrading and even after upgrading but using the previous version of PMD, I think it's a bug on SCA itself (perhaps on the workaround I assume you're doing to make Spotbugs work with Android projects? Should I file a new issue for this Spotbugs behaviour?

I can share a branch to try on..

@barriosnahuel
Copy link
Contributor Author

barriosnahuel commented Apr 22, 2020

We can close it, I added more info at https://issuetracker.google.com/issues/137253405#comment3 (if you need, I can add a new issue for the spotbugs failure)

@jsotuyod
Copy link
Member

jsotuyod commented Apr 22, 2020

To sum up my research into this…

The issue with :my_anroid_dynamic_feature_module:processDebugAndroidTestResources is actually a bug in AGP for dynamic modules. It fails to compile androidTest for that module by not being able to resolve resources from an aar dependency that are actually there. SCA has nothing to do with it, other than simply forcing the task to run, as we need compiled sourced for PMD / Spotbugs analysis. The same issue would arise if you were to simply write an instrumentation test for that module even without SCA. I'd therefore recommend you report that back to https://b.android.com/

As for the issue with no classes for Spotbugs analysis… the problem relies on your project having a non-emtpy Java sourceset, that contains no Java classes (the failing module contains only Kotlin classes in the Java sourceset). As SCA doesn't yet support Kotlin, the Kotlin classes are not being present in the analysis, but as there are files, Spotbugs still believes there is something to analyze and fails…

I do have in backlog to fully support Kotlin in an upcoming 3.x release. In the meantime, you can use the following workaround:

tasks.matching { it.name =~ /^spotbugs.+/ }.configureEach {
  it.onlyIf { !it.classes.empty }
}

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

No branches or pull requests

2 participants