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

Workaround for AGP not merging test manifest #4736

Merged
merged 2 commits into from Mar 8, 2019

Conversation

Projects
None yet
1 participant
@xian
Copy link
Member

commented Mar 8, 2019

Since #4489, Robolectric no longer automatically creates manifest entries for unknown activities, which has led to issues like #4649 and #4640. That's the desired behavior (it's how real Android devices work); however, it should be possible for test authors to declare test-only activities in a test manifest. Unfortunately, Android Gradle Plugin 3.4 (and prior) doesn't merge manifests declared in src/test (see #4726 tracking a fix for that).

This is a workaround for Android Gradle Plugin's failure to merge test manifests.

In order to use test-only activities, you can create a test support gradle project which contains the test activity and declares it in its manifest, then add a testImplementation dependency to to that project. Your dependency graph will be app(test) -> testsupport(main) -> app(main).

app/build.gradle:

dependencies {
  testImplementation ":testsupport"
}

testsupport/build.gradle:

dependencies {
  implementation ":app"
}

See changes for more details.

@xian xian force-pushed the undeclared-activtiy-workaround branch from 0ec795f to 29d1582 Mar 8, 2019

@xian xian changed the title Test for AGP test manifest workaround Test workaround for AGP not merging test manifest Mar 8, 2019

@xian xian added the cla: yes label Mar 8, 2019

@xian xian force-pushed the undeclared-activtiy-workaround branch 2 times, most recently from e2be6af to c824b4d Mar 8, 2019

Test for AGP manifest bug workaround.
Add integration test verifying that activities can be declared in a test support library on which we depend.

See http://issuetracker.google.com/issues/127986458

@xian xian force-pushed the undeclared-activtiy-workaround branch from c824b4d to 6d57524 Mar 8, 2019

Ignore mysterious AGP fail:
> Task :prefetchDependencies FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/usr/local/google/home/christianw/Dev/robolectric-main/build.gradle' line: 159

* What went wrong:
Execution failed for task ':prefetchDependencies'.
> Could not resolve all files for configuration ':integration_tests:agp:debugUnitTestCompileClasspath'.
   > More than one variant of project :integration_tests:agp:testsupport matches the consumer attributes:
       - Configuration ':integration_tests:agp:testsupport:debugApiElements' variant android-aidl:
           - Found artifactType 'android-aidl' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':integration_tests:agp:testsupport:debugApiElements' variant android-classes:
           - Found artifactType 'android-classes' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':integration_tests:agp:testsupport:debugApiElements' variant android-manifest:
           - Found artifactType 'android-manifest' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':integration_tests:agp:testsupport:debugApiElements' variant android-renderscript:
           - Found artifactType 'android-renderscript' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':integration_tests:agp:testsupport:debugApiElements' variant jar:
           - Found artifactType 'jar' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
   > More than one variant of project :integration_tests:agp matches the consumer attributes:
       - Configuration ':integration_tests:agp:debugApiElements' variant android-aidl:
           - Found artifactType 'android-aidl' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':integration_tests:agp:debugApiElements' variant android-classes:
           - Found artifactType 'android-classes' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':integration_tests:agp:debugApiElements' variant android-manifest:
           - Found artifactType 'android-manifest' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':integration_tests:agp:debugApiElements' variant android-renderscript:
           - Found artifactType 'android-renderscript' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':integration_tests:agp:debugApiElements' variant jar:
           - Found artifactType 'jar' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.

@xian xian changed the title Test workaround for AGP not merging test manifest Workaround for AGP not merging test manifest Mar 8, 2019

@xian xian referenced this pull request Mar 8, 2019

Closed

Document workaround for undeclared test activities #4727

3 of 4 tasks complete

@xian xian merged commit a4275f1 into master Mar 8, 2019

7 of 8 checks passed

ci/circleci: test_27_28 Your tests failed on CircleCI
Details
Build (Robolectric) TeamCity build finished
Details
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: test_16_17_18 Your tests passed on CircleCI!
Details
ci/circleci: test_19_21_22 Your tests passed on CircleCI!
Details
ci/circleci: test_23_24 Your tests passed on CircleCI!
Details
ci/circleci: test_25_26 Your tests passed on CircleCI!
Details
import/copybara Import didn't affect any internal file

@xian xian added this to the 4.2.1 milestone Mar 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.