Status Update
Comments
xa...@google.com <xa...@google.com>
je...@google.com <je...@google.com>
je...@google.com <je...@google.com> #2
First, the configuration snippet is not quite right, you wrote :
androidComponents {
finalizeDsl {
onVariants { variant ->
val generateCustomManifestTask = target.tasks.register<GenerateCustomManifestTask>("generate${variant.name.capitalized()}CustomManifest")
variant.androidTest?.sources?.manifests?.addGeneratedManifestFile(generateCustomManifestTask, GenerateCustomManifestTask::manifestProperty)
}
}
}
but it really should be
androidComponents {
onVariants { variant ->
val generateCustomManifestTask = target.tasks.register<GenerateCustomManifestTask>("generate${variant.name.capitalized()}CustomManifest")
variant.androidTest?.sources?.manifests?.addGeneratedManifestFile(generateCustomManifestTask, GenerateCustomManifestTask::manifestProperty)
}
}
The finalizeDsl
block is to finalize the DSL objects before the variants are created. It's just a Gradle DSL quirk that it does not generate an exception as Gradle will look for onVariants
method in the parent hierarchy of the finalizeDsl
block. Of course if finds it in androidComponents
block !
Issues reproducing
In any case, I have tried to reproduce the issue with both the correct configuration and incorrect configuration block and it works fine on my end using 8.4.0 all the way to 8.6.0-dev.
I have attached the full project I used so you can find what's different. If you can modify it to reproduce your issue, that would be great.
It's a bit different than yours because mainly it was easier to use groovy with our current test infrastructure but you will see in the build.gradle
file that I more or less copied your code :
androidComponents {
onVariants(selector().all(), { variant ->
def generateCustomManifestTask = tasks.register("generate${variant.name.capitalize()}CustomManifest", GenerateCustomManifestTask)
if (variant.androidTest != null) {
variant.androidTest.sources.manifests.addGeneratedManifestFile(generateCustomManifestTask, { it.getManifestProperty() })
}
})
}
abstract class GenerateCustomManifestTask extends DefaultTask {
@OutputFile
abstract RegularFileProperty getManifestProperty()
@TaskAction
void generateManifest() {
String manifest = """
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="00000000"
android:versionName="0.0.0">
<permission
android:name="foo.generated.SEND_TEXT"
android:description="@string/app_name"
android:label="@string/app_name"
android:permissionGroup="foo.permission-group.COST_MONEY" />
</manifest>
""".stripIndent()
File manifestFile = manifestProperty.get().asFile
manifestFile.write(manifest)
}
}
Steps to use the sample
- unzip the file
- go to testGeneratedManifestIsUsed/androidManifestInTest folder
- <path_to_gradle>/gradlew assembleDebugAndroidTest
Result
and the resulting merged AndroidManifest.xml
does contain the permission I added above, and the version changes :
~/bugs/341124476/testGeneratedManifestIsUsed/androidManifestInTest cat ./build/intermediates/packaged_manifests/debugAndroidTest/processDebugAndroidTestManifest/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.tests.basic.test"
android:versionCode="00000000"
android:versionName="0.0.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<permission
android:name="foo.generated.SEND_TEXT"
android:description="@string/app_name"
android:label="@string/app_name"
android:permissionGroup="foo.permission-group.COST_MONEY" />
<instrumentation
android:name="android.support.test.runner.AndroidJUnitRunner"
android:functionalTest="false"
android:handleProfiling="false"
android:label="Tests for com.android.tests.basic"
android:targetPackage="com.android.tests.basic" >
<meta-data
android:name="listener"
android:value="android.support.test.internal.runner.listener.ManifestListener" />
</instrumentation>
<permission-group
android:name="foo.permission-group.COST_MONEY"
android:description="@string/app_name"
android:label="@string/app_name" />
<permission
android:name="foo.permission.RECEIVED_SMS"
android:description="@string/app_name"
android:label="@string/app_name"
android:permissionGroup="foo.permission-group.COST_MONEY" />
<application
android:debuggable="true"
android:extractNativeLibs="true" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>%
je...@google.com <je...@google.com> #3
functional project attached.
jo...@dropbox.com <jo...@dropbox.com> #4
Thank you for the sample project. I did run it & can see that the attributes from the generated manifest get merged. However, this is because you have an existing AndroidManifest.xml
in the androidTest
sourceset. If you delete the existing AndroidManifest.xml
, the generated attributes disappear from the merged manifest.
It seems like having an existing AndroidManifest.xml
in the androidTest
sourceset is required for this work, even if that manifest declares nothing. For example, if I replace the AndroidManifest.xml
at testGeneratedManifestIsUsed/androidManifestInTest/src/androidTest/
, it still works with just:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
However, delete the file & it stops working as the generated AndroidManifest.xml
is no longer merged
je...@google.com <je...@google.com> #5
Ah ok, that make sense, ok so for now you have a workaround.
I will look into fixing this asap.
thanks for the report !
je...@google.com <je...@google.com> #6
reducing to P2 as there is a workaround.
an...@google.com <an...@google.com> #8
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Koala Feature Drop | 2024.1.2 Canary 3
- Android Gradle Plugin 8.6.0-alpha03
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
Description
When using
manifests.addGeneratedManifestFile
on theandroidTest
configuration for aVariant
, the manifest is generated but not merged into the androidTest APK.So if you had a project or configuration plugin that declared:
where
GenerateCustomManifestTask
is:build/generated/generateDebugCustomManifest/AndroidManifest.xml
is generated butbuild/intermediates/packaged_manifests/processDebugAndroidTestManifest/AndroidManifest.xml
has none of the attributes from the generated manifestAGP 8.4.0, since that's when
manifests
was introduced