Skip to content

Commit 69bc3b6

Browse files
committed
Added option (TESTDPC_ALLOW_TEST_ONLY) to allow test-only on manifest.
Test: export TESTDPC_ALLOW_TEST_ONLY=true && ./gradlew assembleDebug && adb install -t ./out/gradle/TestDPC/build/outputs/apk/normal/debug/TestDPC-normal-debug.apk Bug: 177564920 Change-Id: I838c87a9a183534ad239cbc4199dfe2f0a64a21e (cherry picked from commit 6bff255822084f3e56a149f5b89095133d7b02f4)
1 parent 3d94a97 commit 69bc3b6

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

app/build.gradle

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,19 @@ private void stripTestOnlyForBuild(flavor, buildType) {
126126
def manifestPath =
127127
"${buildDir}/intermediates/manifests/full/${flavor}/${buildType}/AndroidManifest.xml"
128128
if (file(manifestPath).exists()) {
129-
def xml = new XmlParser().parse(manifestPath)
130-
def attributeNames = xml.application[0].attributes().collect { it.key }
131-
attributeNames.each {
132-
if (it.getLocalPart() == 'testOnly') {
133-
xml.application[0].attributes().remove(it)
134-
println "Removed testOnly attribute successfully!"
129+
if (System.getenv('TESTDPC_ALLOW_TEST_ONLY') == 'true') {
130+
println "NOT stripping testOnly from manifest because of TESTDPC_ALLOW_TEST_ONLY"
131+
} else {
132+
def xml = new XmlParser().parse(manifestPath)
133+
def attributeNames = xml.application[0].attributes().collect { it.key }
134+
attributeNames.each {
135+
if (it.getLocalPart() == 'testOnly') {
136+
xml.application[0].attributes().remove(it)
137+
println "Removed testOnly attribute successfully!"
138+
}
135139
}
140+
new XmlNodePrinter(new PrintWriter(new FileWriter(manifestPath))).print(xml)
136141
}
137-
new XmlNodePrinter(new PrintWriter(new FileWriter(manifestPath))).print(xml)
138142
}
139143
}
140144

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
3434
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
3535

36+
<!-- NOTE: android:testOnly will be stripped by build.fradle (stripTestOnlyForBuild()) -->
3637
<application
38+
android:testOnly="true"
3739
android:allowBackup="true"
3840
android:icon="@drawable/ic_launcher"
3941
android:banner="@drawable/ic_launcher"

0 commit comments

Comments
 (0)