So we will have our example packages is as follows for your production and staging builds within the gradle product flavors.
productFlavors {
production {
packageName "x(path).x(path).gradleexample"
}
staging {
packageName "x(path).x(path).gradleexample.staging"
}
}
Here is an example of your folder structure some of which may or may not apply to your project but should give you a run down of what is needed.
├── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-web.png
│ ├── java
│ │ └── x(path)
│ │ └── x(path)
│ │ └── gradlebuildexample
│ │ └── MainActivity.java
│ └── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── activity_main.xml
│ ├── menu
│ │ └── main.xml
│ ├── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ ├── values-v11
│ │ └── styles.xml
│ └── values-v14
│ └── styles.xml
├── production
│ └── java
│ └── x(path)
│ └── x(path)
│ └── gradlebuildexample
│ └── Constants.java
└── staging
├── java
│ └── x(path)
│ └── x(path)
│ └── gradlebuildexample
│ └── Constants.java
└── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
└── values
└── string.xml
Now to be clear your string result set xml in the production and staging, among the values -> string.xml, will have to contain the following value appropriate for the manifest which will be described below.
So something like as follows
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="receiver">false</string>
</resources>
With my current understanding of your manifest it would look something like this
<receiver
android:name=".appwidget.AppWidgetProvider"
android:label="@string/app_name"
android:enabled="@string/receiver">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/appwidget_info" />
</receiver>
So this would work, but if you saw from my third comment, a much better and simpler solution would be to have a different manifest for each build phase, because you may want more changes than just one. So below I will provide that work around as well which you can extrapolate on what I have provided.
Using source set in gradle you can specify a different build path for each manifest as follows
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
res.srcDirs = ['src/main/res']
}
debug {
manifest.srcFile 'src/main/debug/AndroidManifest.xml'
res.srcDirs = ['src/main/debug/res']
}
release {
manifest.srcFile 'src/main/release/AndroidManifest.xml'
res.srcDirs = ['src/main/release/res']
}
}