-
-
Save lucamtudor/7073992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.trifork.example" | |
android:installLocation="auto" | |
android:versionName="@string/client_info" > | |
<!-- ... --> | |
<application | |
android:hardwareAccelerated="true" | |
android:icon="@drawable/icon" | |
android:label="@string/app_name" | |
android:theme="@style/Theme.Standard" > | |
<!-- ... --> | |
<provider | |
android:name="path.to.provider.ProviderImpl" | |
android:authorities=".res-auto.path.to.provider.ProviderImpl" | |
android:exported="false" > | |
</provider> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:0.6.+' | |
} | |
} | |
apply plugin: 'android' | |
apply from: './build_extras.gradle' | |
repositories { | |
mavenCentral() | |
} | |
android { | |
compileSdkVersion 18 | |
buildToolsVersion "18.0.1" | |
defaultConfig { | |
minSdkVersion 10 | |
targetSdkVersion 18 | |
} | |
} | |
dependencies { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Additional changes to build scripts | |
* | |
* Add support for installing multiple variants of the same app which have a | |
* content provider. Do this by overriding occurrences of ".res-auto" in | |
* android:authorities with the current package name (which should be unique) | |
* | |
* WARNING: Having authorities in strings.xml hasn't been tested, but properly | |
* doesn't work. | |
*/ | |
def overrideProviderAuthority(buildVariant) { | |
def flavor = buildVariant.productFlavors.get(0).name | |
def buildType = buildVariant.buildType.name | |
def pathToManifest = "${buildDir}/manifests/${flavor}/${buildType}/AndroidManifest.xml" | |
def ns = new groovy.xml.Namespace("http://schemas.android.com/apk/res/android", "android") | |
def xml = new XmlParser().parse(pathToManifest) | |
def variantPackageName = xml.@package | |
// Update all content providers | |
xml.application.provider.each { provider -> | |
def newAuthorities = provider.attribute(ns.authorities).replaceAll('.res-auto', variantPackageName) | |
provider.attributes().put(ns.authorities, newAuthorities) | |
} | |
// Save modified AndroidManifest back into build dir | |
def writer = new FileWriter(pathToManifest) | |
def printer = new XmlNodePrinter(new PrintWriter(writer)) | |
printer.preserveWhitespace = true | |
printer.print(xml) | |
} | |
// Post proccessing of AndroidManifest.xml for supporting provider authorities | |
// across build variants. | |
android.applicationVariants.all { variant -> | |
variant.processManifest.doLast { | |
overrideProviderAuthority(variant) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment