Skip to content

Commit 1d3055b

Browse files
author
arangelov
committed
Remove testOnly="true" from TestDPC's intermediate manifest xmls.
Bug: 124859255 Test: adb install does not ask for the -t flag Change-Id: I8992d7f0e01d451f11d69d8dfd009ca32e4dcf05
1 parent 7313116 commit 1d3055b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

app/build.gradle

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,53 @@ android {
7575
output.assemble.dependsOn lintTask
7676
}
7777
}
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+
}
78125
}
79126

80127
dependencies {

0 commit comments

Comments
 (0)