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

Android Project Support - Fix manifest merge task being skipped #58

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

Conversation

jkasten2
Copy link

@jkasten2 jkasten2 commented Oct 13, 2017

Issue

This plugin is not compatible with Android projects as the com.android.application gradle plugin adds tasks and steps up it's depencies on the project.afterEvaluate event as well. The existing logic on whether to apply rules or not is done by checking config.allDependencies.isEmpty(). This will be empty for the processDebugResources task for example. processReleaseResources is executed when calling the standard build task on an Android project.

Note that ./gradlew app:dependencies --configuration compile works fine, however tasks that do manifest merging fail. For example if we use mismatched versions of the com.android.support group in the main app's build.gradle but try to create an alignment rule to sync them it won't be applied to the processReleaseResources task and following error will throw:

Caused by: java.lang.RuntimeException: Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.0) from [com.android.support:appcompat-v7:26.0.0] AndroidManifest.xml:28:13-35
	is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0).
	Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml to override.
	at com.android.builder.core.AndroidBuilder.mergeManifestsForApplication(AndroidBuilder.java:509)
	at com.android.build.gradle.tasks.MergeManifests.doFullTaskAction(MergeManifests.java:150)
	at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:179)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:135)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:122)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
	... 28 more

The following test reproduces this issue.
https://github.com/nebula-plugins/gradle-resolution-rules-plugin/pull/58/files#diff-c71d74290a4498733d4ad203fc844abaR393

Solutions

Solution 1

This is the one that is implemented in this pull.
Add a delay fallback on the project.gradle.taskGraph.afterTask when the rules are applied. In my testing I found that this is run after the Android plugin sets up the dependencies on it's tasks. Since this doesn't pass all existing tests with the delayed event on it's own we need to keep the project.onExecute event.

Solution 2

Another solution would be to simply remove the config.allDependencies.isEmpty() check. However it looks like this was put into place due to performance reasons.

TODO

  • Investigate if project.onExecute can be delayed so config.allDependencies are fully resolved by any other gradle plugins.
  • Add a unit test reproducing the issue
  • Fix failing "Skipping dependency rules for configuration \':compile\' - No dependencies are configured" test

@jkasten2 jkasten2 changed the title Fixing issue with skipping manifest merge task Fixing issue with skipping manifest merge task [WIP] Oct 13, 2017
@jkasten2 jkasten2 force-pushed the android_compatibility branch 6 times, most recently from b36f602 to 084ece7 Compare October 16, 2017 09:37
* Fixed issue where rules were not applied to all Android tasks
   - Rules where not applying as android plugin had not added it's task dependencies yet
   - This was due to gradle plugin 'com.android.application' also replying on project.afterEvaluate
   - Rules are now applied on project.gradle.taskGraph.afterTask instead
@jkasten2 jkasten2 force-pushed the android_compatibility branch from 084ece7 to 5a4e3e1 Compare October 16, 2017 10:12
@jkasten2 jkasten2 changed the title Fixing issue with skipping manifest merge task [WIP] Android Project Support - Fix manifest merge task being skipped Oct 16, 2017
@jkasten2
Copy link
Author

@DanielThomas I just completed this pull request, could you give it a review?

This plugin solves a number of common gradle dependency issues and would be a great help to Android developers if they could use it as well! Specifically around having group alignment for the Android Support Library and Google Play Services Library since each includes a number of modules per group.

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.

1 participant