Last active
August 29, 2015 14:24
-
-
Save numa08/043b21e55b45eacfebef to your computer and use it in GitHub Desktop.
Gradleあれこれ
This file contains hidden or 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
// サブプロジェクト `app` のbuild.gradle | |
apply plugin: 'com.android.application' | |
apply plugin: 'android-apt' | |
apply plugin: 'io.fabric' | |
apply plugin: 'com.github.triplet.play' | |
// CI環境でバージョン番号を自動的につけるための設定 | |
def versionNumber = (System.getenv()['BUILD_NUMBER'] ?: 1) as Integer | |
def versionDescription = System.getenv()['ghprbSourceBranch'] ?: "git symbolic-ref --short HEAD".execute().text.trim() | |
android { | |
compileSdkVersion 22 | |
buildToolsVersion "22.0.1" | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_7 | |
targetCompatibility JavaVersion.VERSION_1_7 | |
} | |
adbOptions { | |
timeOutInMs 10 * 60 * 1000 | |
} | |
defaultConfig { | |
applicationId "com.covelline.xxx" | |
minSdkVersion 16 | |
targetSdkVersion 22 | |
versionCode 1 | |
versionName "0.1" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
ndk { | |
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips" | |
} | |
} | |
// プロダクトフレイバーでα版、β版、製品版向けにパッケージ名などを変更 | |
productFlavors { | |
alpha { | |
applicationId defaultConfig.applicationId + ".alpha" | |
versionCode versionNumber | |
versionName defaultConfig.versionName + "-alpha.${versionDescription}" | |
ext.betaDistributionGroupAliases="feather-android-alpha" | |
resValue("string", "app_name", "feather-alpha.${versionNumber}") | |
} | |
beta { | |
applicationId defaultConfig.applicationId + ".beta" | |
versionCode versionNumber | |
versionName defaultConfig.versionName + "-beta.${versionDescription}" | |
ext.betaDistributionGroupAliases="feather-android-beta" | |
resValue("string", "app_name", "feather-beta#${versionNumber}") | |
} | |
prod { | |
applicationId defaultConfig.applicationId | |
versionName defaultConfig.versionName | |
resValue("string", "app_name", "feather") | |
} | |
} | |
signingConfigs { | |
release { | |
storeFile file("../../../misc/secure/covelline.keystore") | |
storePassword "xxx" | |
keyAlias "xxx" | |
keyPassword "xxx" | |
} | |
debug { | |
storeFile file("../../../misc/secure/debug.keystore") | |
} | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
signingConfig signingConfigs.release | |
} | |
debug { | |
signingConfig signingConfigs.debug | |
} | |
} | |
// 依存しているライブラリがもつJarの中に同じファイルがあるとビルドに失敗するので、対策 | |
packagingOptions { | |
exclude 'META-INF/LICENSE.txt' | |
exclude 'LICENSE.txt' | |
exclude 'META-INF/NOTICE.txt' | |
} | |
lintOptions { | |
disable 'RtlEnabled','RtlHardcoded' | |
lintConfig file("lint.xml") | |
} | |
dexOptions { | |
// CI向け設定 | |
preDexLibraries !(System.getenv()["CI"] as boolean) | |
javaMaxHeapSize "4096M" | |
} | |
testOptions { | |
unitTests.all { | |
maxParallelForks 1 | |
} | |
unitTests.returnDefaultValues = true | |
} | |
} | |
def AAVersion = '3.3.1' | |
// 依存関係 | |
dependencies { | |
compile fileTree(include: ['*.jar'], dir: 'libs') | |
compile project(':feather-twitter') | |
compile 'de.greenrobot:eventbus:2.4.0' | |
compile 'com.android.support:design:22.2.0' | |
compile 'com.joanzapata.android:android-iconify:1.0.8' | |
compile 'com.makeramen:roundedimageview:2.1.1' | |
compile 'com.squareup.picasso:picasso:2.5.2' | |
compile 'com.github.ksoichiro:Android-ObservableScrollView:v1.5.2' | |
compile('com.twitter.sdk.android:twitter:1.3.2@aar') { | |
transitive = true; | |
} | |
apt "org.androidannotations:androidannotations:$AAVersion" | |
compile "org.androidannotations:androidannotations-api:$AAVersion" | |
compile('com.crashlytics.sdk.android:crashlytics:2.2.4@aar') { | |
transitive = true | |
} | |
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' | |
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' | |
testCompile 'org.robolectric:robolectric:3.0-rc3' | |
testCompile 'org.mockito:mockito-core:1.10.19' | |
// Testing-only dependencies | |
androidTestCompile ('com.android.support.test:runner:0.2') { | |
exclude group:'com.android.support', module:'support-annotations' | |
} | |
// Set this dependency to use JUnit 4 rules | |
androidTestCompile ('com.android.support.test:rules:0.2') { | |
exclude group:'com.android.support', module:'support-annotations' | |
} | |
// Set this dependency to build and run Espresso tests | |
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.1') { | |
exclude group:'com.android.support', module:'support-annotations' | |
} | |
androidTestCompile 'org.mockito:mockito-core:1.10.19' | |
} | |
apt { | |
arguments { | |
androidManifestFile variant.outputs[0].processResources.manifestFile | |
resourcePackageName android.defaultConfig.applicationId | |
} | |
} |
This file contains hidden or 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
// プロジェクトのルートディレクトリのbuild.gradle | |
buildscript { | |
repositories { | |
jcenter() | |
maven { url 'https://maven.fabric.io/public' } | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:1.2.3' | |
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' | |
classpath 'io.fabric.tools:gradle:1.19.0' | |
classpath 'com.github.triplet.gradle:play-publisher:1.1.0' | |
} | |
} | |
allprojects { | |
repositories { | |
// プロジェクト全体で利用したいMavenレポジトリのURL | |
jcenter() | |
maven { url 'https://maven.fabric.io/public' } | |
maven { url "https://jitpack.io" } | |
mavenCentral() | |
} | |
} |
This file contains hidden or 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
// feather-twitter をテストするためのアプリケーションプロジェクト `feather-twitter-test` プロジェクトのbuild.gradle | |
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 22 | |
buildToolsVersion "22.0.1" | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_7 | |
targetCompatibility JavaVersion.VERSION_1_7 | |
} | |
defaultConfig { | |
applicationId "xxx" | |
minSdkVersion 16 | |
targetSdkVersion 22 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
packagingOptions { | |
exclude 'LICENSE.txt' | |
exclude 'META-INF/LICENSE.txt' | |
exclude 'META-INF/NOTICE.txt' | |
} | |
testOptions { | |
unitTests.returnDefaultValues = true | |
} | |
} | |
dependencies { | |
compile project(':feather-twitter') | |
testCompile 'org.robolectric:robolectric:3.0-rc3' | |
testCompile 'org.mockito:mockito-core:1.10.19' | |
testCompile 'com.android.support:appcompat-v7:22.2.0' | |
// Testing-only dependencies | |
androidTestCompile ('com.android.support.test:runner:0.2') { | |
exclude group:'com.android.support', module:'support-annotations' | |
} | |
// Set this dependency to use JUnit 4 rules | |
androidTestCompile ('com.android.support.test:rules:0.2') { | |
exclude group:'com.android.support', module:'support-annotations' | |
} | |
// Set this dependency to build and run Espresso tests | |
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.1') { | |
exclude group:'com.android.support', module:'support-annotations' | |
} | |
} |
This file contains hidden or 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
// ライブラリプロジェクト `feather-twitter` のbuild.gradle | |
apply plugin: 'com.android.library' | |
android { | |
compileSdkVersion 22 | |
buildToolsVersion "22.0.1" | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_7 | |
targetCompatibility JavaVersion.VERSION_1_7 | |
} | |
defaultConfig { | |
minSdkVersion 16 | |
targetSdkVersion 22 | |
versionCode 1 | |
versionName "1.0" | |
ndk { | |
moduleName "appidentifier" | |
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips" | |
stl "gnustl_static" | |
} | |
} | |
packagingOptions { | |
exclude 'LICENSE.txt' | |
exclude 'META-INF/LICENSE.txt' | |
exclude 'META-INF/NOTICE.txt' | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
lintOptions { | |
disable 'RtlEnabled','RtlHardcoded' | |
lintConfig file("lint.xml") | |
} | |
testOptions { | |
unitTests.returnDefaultValues = true | |
} | |
} | |
dependencies { | |
compile fileTree(include: ['*.jar'], dir: 'libs') | |
compile 'com.android.support:appcompat-v7:22.2.0' | |
compile 'io.realm:realm-android:0.81.1' | |
compile 'org.twitter4j:twitter4j-core:4.0.4' | |
compile 'commons-io:commons-io:2.4' | |
compile 'org.apache.commons:commons-lang3:3.4' | |
compile 'com.google.guava:guava:18.0' | |
} |
This file contains hidden or 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
// サブプロジェクト一覧 | |
include ':app', ':feather-twitter', ':feather-twitter-test' |
This file contains hidden or 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
. | |
├── app | |
│ ├── app.iml | |
│ ├── build.gradle | |
│ ├── fabric.properties | |
│ ├── lint.xml | |
│ ├── proguard-rules.pro | |
│ └── src | |
├── build.gradle | |
├── feather-twitter | |
│ ├── build.gradle | |
│ ├── feather-twitter.iml | |
│ ├── lint.xml | |
│ ├── proguard-rules.pro | |
│ └── src | |
├── feather-twitter-test | |
│ ├── build.gradle | |
│ ├── feather-twitter-test.iml | |
│ └── src | |
├── feather.iml | |
├── gradle | |
│ └── wrapper | |
├── gradle.properties | |
├── gradlew | |
├── gradlew.bat | |
├── local.properties | |
└── settings.gradle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
アプリケーションプロジェクト
app
はライブラリプロジェクトfeather-twitter
に依存をしています。UIなどAndroidのコンポーネントに強く依存する部分をapp
に、それ以外のModelなどをfeather-twitter
で開発をしています。ライブラリプロジェクトは単体ではテストをすることができないので、
feather-twitter-test
というアプリケーションプロジェクトを作ってテストを行います。feather-twitter-test
はテスト専用のアプリケーションプロジェクトなので、app
のバイナリに含まれることはありません。gradle
の実行にはgradlew
を利用します。gradle.properties
に設定を記入しておくことで環境に依存することなく指定したバージョンのgradle
を実行することができるためです。その他、CI環境でテストの実行を行うためやパフォーマンスを出すための設定を行っています。
以前書いた CircleCiでAndroid開発を爆速にする | Covelline Developer Blog や Tips - Android Tools Project Site を参考にいろいろとやってみてください。