Skip to content

Instantly share code, notes, and snippets.

@kimukou

kimukou/build.gradle

Last active Jul 24, 2017
Embed
What would you like to do?
ADT_compatible_gradle_2017_07_20
//=============ココらへん記述でコマンドラインは通る ==========
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://plugins.gradle.org/m2/" }
//google() //support gradle runtime 4.0 upper
maven { url 'https://maven.google.com' }
}
dependencies {
//need gradle-2.14.1-bin.zip
classpath 'com.android.tools.build:gradle:2.1.+' // 現状だと2.1.3
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.github.gfx.ribbonizer:plugin:1.0.0'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.10'
}
configurations.all {
resolutionStrategy {
force 'net.sf.proguard:proguard-gradle:5.3.3'
}
}
}
//=============ココらへん記述でコマンドラインは通る ==========
apply from: 'init.gradle'
//=======================================================================================
apply plugin: 'com.android.application'
// res => src/main/res に AndroidManifest.xmlで指定されている ic_laouncher.png があればOK
apply plugin: 'com.github.gfx.ribbonizer'
//apply plugin: 'net.ltgt.errorprone'
//apply plugin: 'io.github.retropiler'
import com.android.builder.core.DefaultManifestParser
android {
//see http://mrhaki.blogspot.jp/2010/01/groovy-goodness-check-if-string-is.html
if(_compileSdkVersion.isNumber()){
compileSdkVersion _compileSdkVersion as int //数値の場合はコチラで指定する
}
else{
compileSdkVersion "$_compileSdkVersion"
}
buildToolsVersion "$_buildToolsVersion"
useLibrary 'org.apache.http.legacy' //24以上指定したときは有効化する or Okhttp等別途通信ライブラリを導入する
signingConfigs {
/*
署名用のキーストアファイルからdebug用のkeyを作成
irof.keystore => irof_debug.keystore をコピーして作成
$ keytool -storepasswd -keystore irof_debug.keystore
android
$ keytool -changealias -alias irof_history -keystore irof_debug.keystore
androiddebugkey
$ keytool -keypasswd -alias androiddebugkey -keystore irof_debug.keystore
android
*/
debug {
storeFile file('./irof_debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release {
storeFile file('./irof.keystore')
storePassword "XXXXXX"
keyAlias "irof_history"
keyPassword "XXXXXX!"
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
aaptOptions.cruncherEnabled = false
testCoverageEnabled false
debuggable true
applicationIdSuffix ".debug"
versionNameSuffix "-DEBUG"
//=== Built-in Shrinker ===
debuggable true
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
//=== Built-in Shrinker ===
}
release {
debuggable false
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
releaseLOG.initWith(buildTypes.release)
releaseLOG{
buildConfigField "Boolean", "LOG_DEBUG", 'true'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
res.srcDirs = ['res']
}
instrumentTest.setRoot('tests')
//debug.setRoot('build-types/debug')
//release.setRoot('build-types/release')
// 実行時に差分ファイルのコピー
// antの build.xmlとかだと上書きするやつ
release.res.srcDirs += ['build-types/release/res']
//productFlavorを使うときは
// see http://qiita.com/sis-yoshiday/items/2b43e4635bbbb059d970
}
defaultConfig {
//use 2.1.2 まで?
if(false){
def manifestParser = new DefaultManifestParser()
applicationId = manifestParser.getPackage(android.sourceSets.main.manifest.srcFile)
versionName = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
def manifest = new XmlSlurper().parse(android.sourceSets.main.manifest.srcFile)
versionCode manifest.'@android:versionCode'.text() as int
minSdkVersion manifestParser.getMinSdkVersion(android.sourceSets.main.manifest.srcFile)
targetSdkVersion manifestParser.getTargetSdkVersion(android.sourceSets.main.manifest.srcFile)
}
else{
def manifestParser = new DefaultManifestParser(android.sourceSets.main.manifest.srcFile)
applicationId = manifestParser.getPackage()
versionName = manifestParser.getVersionName()
versionCode manifestParser.getVersionCode()
minSdkVersion manifestParser.getMinSdkVersion()
targetSdkVersion manifestParser.getTargetSdkVersion()
}
}
//javaのコンパイラの設定
compileOptions {
encoding "UTF-8"
sourceCompatibility _JavaVersion as org.gradle.api.JavaVersion
targetCompatibility _JavaVersion as org.gradle.api.JavaVersion
}
dexOptions {
preDexLibraries = true
jumboMode = true
threadCount = 4
//javaMaxHeapSize "2g"
}
lintOptions {
checkReleaseBuilds false
quiet true
abortOnError false
ignoreWarnings true
disable 'LongLogTag'
disable 'GradleCompatible'
disable 'InnerclassSeparator'
}
packagingOptions {
exclude 'META-INF/MANIFEST.MF'
}
def applicationId = defaultConfig.applicationId
android.applicationVariants.all{ variant ->
if (variant.buildType.name.equals("release")) {
variant.outputs.each { output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
// Rename APK
def versionName = defaultConfig.versionName
def date = new java.text.SimpleDateFormat("yyyyMMdd_HHmm").format(new Date())
def newName = "${applicationId}_ver.${versionName}_${date}.apk"
if (output.hasProperty('outputFileName')) {
output.outputFileName = newName
}
else{
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
}
}
}
repositories {
// TODO:マルチプロジェクトは不安定なので aarにして参照する ■
flatDir {
dirs 'libs_aar'
}
}
dependencies {
compile fileTree(dir: 'libs', includes: ['*.jar'])
if (_playServicesVersion.compareTo("6.5") < 0) {
// TODO: 勿論 multiprojectにして下記な参照方法もあるが、gitはファイルの位置を移動すると差分比較ができない
// compile(':google-play-services_lib_froyo_rev12')
compile(name:'google-play-services_lib_froyo_rev12-debug', ext:'aar') //
}
else{
//分割参照バージョン
// see http://exception-think.hatenablog.com/entry/20160810/1470754800
compile "com.google.android.gms:play-services-location:$_playServicesVersion"
compile "com.google.android.gms:play-services-maps:$_playServicesVersion"
}
//support library
compile "com.android.support:support-v4:$_supportLibraryVersion"
compile 'commons-lang:commons-lang:2.6'
compile 'com.google.guava:guava:14.0.1'
compile 'com.google.code.gson:gson:2.8.1'
}
// google-play-services_lib_froyo_rev12/build.gradle
// google-play-services_lib_froyo_rev12のaarを作成するために、buildscript部分を追記
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.+'
}
}
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
publishNonDefault true
defaultPublishConfig "debug"
compileSdkVersion 26
buildToolsVersion "26.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
#Fri Jan 20 12:16:31 JST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
org.gradle.daemon=true
# use jdk7 on OS
#org.gradle.jvmargs=-Xms1024m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# use jdk8 on OS
org.gradle.jvmargs=-Xms1024m -Xmx1024m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.workers.max=4
org.gradle.parallel=true
# === using 3.0 is disable ====
#org.gradle.configureondemand=false
#_compileSdkVersion=26
_compileSdkVersion=Google Inc.:Google APIs:23
#_buildToolsVersion=26.0.0
_buildToolsVersion=25.0.3
_playServicesVersion=8.4.0
#_playServicesVersion=11.0.2
_supportLibraryVersion=25.3.1
#_supportLibraryVersion=24.2.+
# === using 3.0 is disable ====
org.gradle.caching=true
#android.enableBuildCache=false
_JavaVersion=VERSION_1_7
#_JavaVersion=VERSION_1_8
// TODO: root/build.gradle と同一のもの
//============= apply from: 'init.gradle' 経由だと無視される ==========
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://plugins.gradle.org/m2/" }
//google() //support gradle runtime 4.0 upper
maven { url 'https://maven.google.com' }
}
dependencies {
//need gradle-2.14.1-bin.zip
classpath 'com.android.tools.build:gradle:2.1.+' // 現状だと2.1.3
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.github.gfx.ribbonizer:plugin:1.0.0'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.10'
}
configurations.all {
resolutionStrategy {
force 'net.sf.proguard:proguard-gradle:5.3.3'
}
}
}
//============= apply from: 'init.gradle' 経由だと無視される ==========
allprojects {
repositories {
jcenter()
//mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
//google() //support gradle runtime 4.0 upper
maven { url 'https://maven.google.com' }
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
if ( it.source.asPath.indexOf("generated") != -1 ){
options.compilerArgs << "-Xmaxerrs" << "500"
//[TODO] use errorprone plugin
//options.compilerArgs << '-XepDisableWarningsInGeneratedCode'
}
else {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
//[TODO] errorphone
//options.compilerArgs << '-Werror'
//options.compilerArgs += [ '-Xep:DeadException:WARN', '-Xep:GuardedByValidator:OFF' ]
}
}
}
task build_tasks << {
def list = []
tasks.findAll { it.group == "build" }.unique(false) { it.name }.each { task ->
list.add(task.name);
}
list.unique(false).each{
println(it)
}
}
tasks.whenTaskAdded { task ->
if (task.name.indexOf("Test")!=-1) {
task.enabled = false
}
if (task.name.indexOf("assemble")!=-1) {
task.group = "build"
}
if (task.name.indexOf("crashlytics")!=-1) {
task.group = "build"
}
if (task.name.indexOf("clean")!=-1) {
task.group = "build"
}
}
}
task showVersion {
println "[android plugin version]" + buildscript.configurations.classpath.resolvedConfiguration.firstLevelModuleDependencies.moduleVersion
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment