Skip to content

Instantly share code, notes, and snippets.

@shikajiro
Created February 16, 2015 15:09
Show Gist options
  • Save shikajiro/0efc779cfa67baf04586 to your computer and use it in GitHub Desktop.
Save shikajiro/0efc779cfa67baf04586 to your computer and use it in GitHub Desktop.
Android新規プロジェクト時のbuild.gradleのテンプレート
//build.gradleのテンプレート
/*root*/
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath 'com.deploygate:gradle:0.6'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'com.jakewharton.hugo:hugo-plugin:1.1.0'
classpath 'com.eowise:gradle-imagemagick:0.3.0'
classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
}
}
allprojects {
repositories {
jcenter()
}
}
/*画像をsvgから各サイズに書き出すタスク
全ての解像度向けに出力するには
./gradlew buildIconsAll
個別街道度向けに出力するには
./gradlew buildIconsMdpi
のように実行する。
※実行するときはAndroidStudioや別タスクのキャッシュに注意すること。
*/
def dpis = [
[ variant: 'mdpi', density:90], //90を基準の1として扱う
[ variant: 'hdpi', density:135 ],
[ variant: 'xhdpi', density:180 ],
[ variant: 'xxhdpi', density:270 ],
[ variant: 'xxxhdpi', density:360 ]
];
//解像度個別タスクの作成
dpis.each {
item ->
task("buildIcons${item.variant.capitalize()}", type: com.eowise.imagemagick.tasks.Magick) {
//svgファイルは以下のディレクトリにシンボリックリンクを貼っている
convert 'resources/icons/', { include '*.svg' }
into "app/src/main/res/drawable-${item.variant}"
actions {
-density(item.density)
-background('none')
inputFile()
// -resize(item.size) 単純なサイズだと解像度が落ちるのでdensityを利用している
outputFile { filename, extension -> "${filename.replace("-", "_").toLowerCase()}.png" }
}
}
}
//解像度一括出力のタスク
task buildIconsAll << {
dpis.each{
item ->
tasks["buildIcons${item.variant.capitalize()}"].execute()
}
}
/* app */
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'deploygate'
apply plugin: 'crashlytics'
apply plugin: 'hugo'
configurations {
apt
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
encoding "UTF-8"
}
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "jp.shikajiro.hogehoge"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
}
signingConfigs {
debug {
storeFile file("keystore/debug.keystore")
}
release
}
buildTypes {
debug{
debuggable true
minifyEnabled false
applicationIdSuffix ".debug"
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile file('proguard-rules.txt')
}
release {
minifyEnabled false
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile file('proguard-rules.txt')
// gradle.properties にリリース署名用の設定があれば署名を有効化します。設定のサンプルとして gradle.properties.forReleaseSigning を置いたので参考にしてください。
if (project.hasProperty('storeFile')) {
signingConfig signingConfigs.release
}
}
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'jp.shikajiro.hogehoge'
// If you're using Android NBS flavors you should use the following line instead of hard-coded packageName
// resourcePackageName android.defaultConfig.packageName
// You can set optional annotation processing options here, like these commented options:
// logLevel 'INFO'
// logFile '/var/log/aa.log'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
//Google Play Service Map,
compile "com.google.android.gms:play-services:6.5.87"
//処理共通化ライブラリ
compile "com.google.guava:guava:18.0"
//json
compile "com.google.code.gson:gson:2.3.1"
//日付
compile "net.danlew:android.joda:2.7.0"
//Google Api
compile 'com.google.api-client:google-api-client:1.18.0-rc'
//multidex対応
compile 'com.android.support:multidex:1.0.0'
//DB
compile('de.greenrobot:greendao:1.3.+'){
exclude module: 'support-v4'
}
//ソースコードダイエット
apt "org.androidannotations:androidannotations:3.0.1"
compile "org.androidannotations:androidannotations-api:3.0.1"
//EventBus
compile "com.squareup:otto:1.3.4"
//通信
compile "com.mcxiaoke.volley:library:1.0.10"
compile "com.squareup.retrofit:retrofit:1.9.0"
//ログ
compile 'com.jakewharton.timber:timber:2.5.1'
//デバッグ
compile "com.deploygate:sdk:3.1"
//csv
compile "net.sf.opencsv:opencsv:2.3"
//crashlytics
compile 'com.crashlytics.android:crashlytics:1.+'
}
/*テスト*/
//Android Studio の Android Studio Unit Test Pluginを利用すること
// ./gradlew test で 単体テスト
// ./gradlew connectedAndroidTest で UIテスト
apply plugin: 'android-unit-test'
dependencies {
repositories {
mavenCentral()
}
// Espresso
// androidTestCompile('com.android.support.test.espresso:espresso-core:2.0')
// androidTestCompile('com.android.support.test:testing-support-lib:0.1')
// Robotium
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
androidTestCompile "org.mockito:mockito-core:1.10.19"
// Robolectric
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile 'org.hamcrest:hamcrest-integration:1.1'
testCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
}
if (project.hasProperty('storeFile')) {
android.signingConfigs.release.storeFile = file(storeFile)
}
if (project.hasProperty('storePassword')) {
android.signingConfigs.release.storePassword = storePassword
}
if (project.hasProperty('keyAlias')) {
android.signingConfigs.release.keyAlias = keyAlias
}
if (project.hasProperty('keyPassword')) {
android.signingConfigs.release.keyPassword = keyPassword
}
//./gradlew build; ./gradlew uploadDeployGate -PdeploygateMsg="deploygateメッセージ"
deploygate {
userName = "shikajiro"
token = "*****"
apks {
release {
sourceFile = file("build/outputs/apk/app-release.apk")
message = deploygateMsg
}
debug {
sourceFile = file("build/outputs/apk/app-debug.apk")
//Below is optional
message = deploygateMsg
//配布ページ用
// distributionKey = "[distribution_key]"
// releaseNote = "release note sample"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment