Skip to content

Instantly share code, notes, and snippets.

@LazerPanther
Forked from cyrilmottier/CityBikesContract.java
Created December 2, 2015 22:44
Show Gist options
  • Save LazerPanther/bf7c6044d88d9449d1a9 to your computer and use it in GitHub Desktop.
Save LazerPanther/bf7c6044d88d9449d1a9 to your computer and use it in GitHub Desktop.
Using the new Gradle-based Android build system: a second example
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyrilmottier.android.avelov"
android:installLocation="auto">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-feature
android:name="android.hardware.location"
android:required="false" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/config_app_name"
android:theme="@style/Theme.CityBikes">
<!-- -->
<!-- Activities -->
<!-- -->
<!-- ... -->
<!-- -->
<!-- Providers -->
<!-- -->
<provider
android:authorities="@string/config_authority"
android:exported="false"
android:name="com.cyrilmottier.android.citybikes.provider.CityBikesProvider" />
<!-- -->
<!-- Google Maps Android API v2 keys -->
<!-- -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/config_com.google.android.maps.v2.api_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="config_app_name">AVélib Debug</string>
<string name="config_authority">com.cyrilmottier.android.avelib.citybikes.debug</string>
<string name="config_com.google.android.maps.v2.api_key">XXX</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="config_app_name">AVélib</string>
<string name="config_authority">com.cyrilmottier.android.avelib.citybikes</string>
<string name="config_com.google.android.maps.v2.api_key">XXX</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="config_app_name">AVélov Debug</string>
<string name="config_authority">com.cyrilmottier.android.avelov.citybikes.debug</string>
<string name="config_com.google.android.maps.v2.api_key">XXX</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="config_app_name">AVélov</string>
<string name="config_authority">com.cyrilmottier.android.avelov.citybikes</string>
<string name="config_com.google.android.maps.v2.api_key">XXX</string>
</resources>
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.squareup.retrofit:retrofit:1.2.2'
}
def versionMajor = 2
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0
def gitSha() {
def res = 'git rev-parse HEAD'.execute([], project.rootDir).text.trim()
def diff = 'git diff'.execute([], project.rootDir).text.trim()
if (diff != null && diff.length() > 0) {
res += "-dirty"
}
return res
}
android {
compileSdkVersion 18
buildToolsVersion '19'
defaultConfig {
buildConfigField "String", "GIT_SHA", "\"${gitSha()}\""
minSdkVersion 14
targetSdkVersion 19
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}" + ((versionPatch != 0) ? ".${versionPatch}" : "")
}
signingConfigs {
debug {
storeFile file("../distribution/debug.keystore")
}
release {
storeFile file("../distribution/release.keystore")
storePassword "XXX"
keyAlias "XXX"
keyPassword "XXX"
}
}
productFlavors {
avelov {
packageName = "com.cyrilmottier.android.avelov"
}
avelib {
packageName = "com.cyrilmottier.android.avelib"
}
}
buildTypes {
debug {
packageNameSuffix ".debug"
signingConfig signingConfigs.debug
versionNameSuffix "-debug"
}
release {
proguardFile 'config.proguard'
runProguard true
signingConfig signingConfigs.release
}
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.9'
}
package com.cyrilmottier.android.citybikes.provider;
import android.net.Uri;
import com.cyrilmottier.android.avelov.BuildConfig;
/**
* @author Cyril Mottier
*/
public class CityBikesContract {
public static final String CONTENT_AUTHORITY = buildAuthority();
private static String buildAuthority() {
String authority = "com.cyrilmottier.android.";
authority += BuildConfig.FLAVOR;
authority += ".citybikes";
if (BuildConfig.DEBUG) {
authority += ".debug";
}
return authority;
}
public static final Uri CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment