@@ -75,6 +75,53 @@ android {
75
75
output. assemble. dependsOn lintTask
76
76
}
77
77
}
78
+
79
+ task stripTestOnlyNormalDebug << {
80
+ stripTestOnlyForBuild(" normal" , " debug" )
81
+ }
82
+
83
+ task stripTestOnlyNormalRelease << {
84
+ stripTestOnlyForBuild(" normal" , " release" )
85
+ }
86
+
87
+ task stripTestOnlyReplicaDebug << {
88
+ stripTestOnlyForBuild(" replica" , " debug" )
89
+ }
90
+
91
+ task stripTestOnlyReplicaRelease << {
92
+ stripTestOnlyForBuild(" replica" , " release" )
93
+ }
94
+
95
+ tasks. whenTaskAdded { task ->
96
+ if (task. name == " splitsDiscoveryTaskNormalDebug" ) {
97
+ task. dependsOn stripTestOnlyNormalDebug
98
+ } else if (task. name == " splitsDiscoveryTaskNormalRelease" ) {
99
+ task. dependsOn stripTestOnlyNormalRelease
100
+ } else if (task. name == " splitsDiscoveryTaskReplicaDebug" ) {
101
+ task. dependsOn stripTestOnlyReplicaDebug
102
+ } else if (task. name == " splitsDiscoveryTaskReplicaRelease" ) {
103
+ task. dependsOn stripTestOnlyReplicaRelease
104
+ }
105
+ }
106
+ }
107
+
108
+ // Modifies the specified build variant's intermediate AndroidManifest.xml file
109
+ // to remove the testOnly attribute. Used for preventing Gradle from inserting the
110
+ // attribute when TestDPC is compiled with a development Android branch.
111
+ private void stripTestOnlyForBuild (flavor , buildType ) {
112
+ def manifestPath =
113
+ " ${ buildDir} /intermediates/manifests/full/${ flavor} /${ buildType} /AndroidManifest.xml"
114
+ if (file(manifestPath). exists()) {
115
+ def xml = new XmlParser (). parse(manifestPath)
116
+ def attributeNames = xml. application[0 ]. attributes(). collect { it. key }
117
+ attributeNames. each {
118
+ if (it. getLocalPart() == ' testOnly' ) {
119
+ xml. application[0 ]. attributes(). remove(it)
120
+ println " Removed testOnly attribute successfully!"
121
+ }
122
+ }
123
+ new XmlNodePrinter (new PrintWriter (new FileWriter (manifestPath))). print (xml)
124
+ }
78
125
}
79
126
80
127
dependencies {
0 commit comments