Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
gradle.build for dagger2+Glide+RxJava/RxAndroid+OkHttp+RapidORM

Project build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.support_version = "23.1.1"
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

App build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.wangjie.example"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.1"
        manifestPlaceholders = [CHANNEL_VALUE: "MyTest"]

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    signingConfigs {
        release {
            storeFile file(project.property("_storeFile"))
            storePassword project.property("_storePassword")
            keyAlias project.property("_keyAlias")
            keyPassword project.property("_keyPassword")
        }
        debug {
            storeFile file(project.property("_storeFile"))
            storePassword project.property("_storePassword")
            keyAlias project.property("_keyAlias")
            keyPassword project.property("_keyPassword")
        }
    }


    buildTypes {
        release {
            signingConfig signingConfigs.release
            // 开启混淆
            minifyEnabled true
            // 混淆文件
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            // 版本名前缀
            versionNameSuffix ""
            // 开启ZipAlign优化
            zipAlignEnabled true
            // 移除无用的resource文件
            shrinkResources true
            // release模式下,不显示log
            buildConfigField("boolean", "LOG_DEBUG", "false")
        }
        debug {
            signingConfig signingConfigs.debug
            // 开启混淆
            minifyEnabled false
            // 混淆文件
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            // 版本名前缀
            versionNameSuffix "-debug"
            // 不开启ZipAlign优化
            zipAlignEnabled false
            // 不移除无用的resource文件
            shrinkResources false
            // release模式下,不显示log
            buildConfigField("boolean", "LOG_DEBUG", "true")
        }
    }

    productFlavors {
        MyTest{}
        MyTest2{}
        // other channels
    }

    // 批量配置渠道
    productFlavors.all {
        flavor -> flavor.manifestPlaceholders = [CHANNEL_VALUE: name]
    }

    applicationVariants.all {
        variant ->
            variant.outputs.each {
                output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
            }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:$support_version"
    androidTestCompile "com.android.support:support-annotations:$support_version"

    compile "com.android.support:design:$support_version"

    compile project(":AndroidKotlinBucket")

    compile project(":provider")
    
    // ORM
    compile project(":RapidORM")

    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.github.bumptech.glide:okhttp-integration:1.3.1'


    // dagger 2
    compile 'com.google.dagger:dagger:2.0.2'
    apt 'com.google.dagger:dagger-compiler:2.0.2' // java
    provided 'org.glassfish:javax.annotation:10.0-b28'
    
    // okhttp
    compile 'com.squareup.okhttp:okhttp:2.4.0'
//    compile 'com.squareup.okhttp:okhttp-ws:2.4.0'

    // extra reactivex
    compile 'io.reactivex:rxjava:1.0.12'
    compile 'io.reactivex:rxandroid:0.24.0'
    
    // gson
    compile 'com.google.code.gson:gson:2.3.1'

    // testing
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:+'
    androidTestCompile 'com.android.support.test:runner:0.4.1'

    // Set this dependency to use JUnit 4 rules
    androidTestCompile 'com.android.support.test:rules:0.4.1'

    // Set this dependency to build and run UI Automator tests
//    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

    // Set this dependency to build and run Espresso tests
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile ("com.android.support.test.espresso:espresso-contrib:2.2.1") {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.