美文网首页
工程结构优化

工程结构优化

作者: 极客天空 | 来源:发表于2019-11-27 23:01 被阅读0次

在项目根目录下创建 统一版本管理文件 gradle 文件

ext {
    android = [compileSdkVersion: 29,
               buildToolsVersion: "29.0.0",
               minSdkVersion    : 19,
               targetSdkVersion : 29,
               applicationId    : 'com.imooc.imooc_voice',
               versionCode      : 2,
               versionName      : '1.1',
               multiDexEnabled  : true,]
    depsVersion = [appcompact     : '29.0.0',
                   design         : '29.0.0',
                   recyclerview   : '29.0.0',
                   constraint     : '1.1.3',
                   eventbus       : '3.1.1',
                   greendao       : '3.2.2',
                   rxjava         : '2.2.9',
                   rxandroid      : '2.1.1',
                   arouterapi     : '1.5.0',
                   aroutercompiler: '1.2.2',
                   magicindicator : '1.5.0',
                   glide          : '4.9.0',
                   glidecompiler  : '4.9.0',
                   okhttp         : '3.3.0',
                   gson           : '2.8.0',
    ]

    depsLibs = [appcompact     : 'androidx.appcompat:appcompat:1.0.0',
                design         : 'com.google.android.material:material:1.0.0',
                recyclerview   : 'androidx.recyclerview:recyclerview:1.0.0',
                constraint     : 'androidx.constraintlayout:constraintlayout:1.1.3',
                eventbus       : "org.greenrobot:eventbus:${depsVersion.eventbus}",
                greendao       : "org.greenrobot:greendao:${depsVersion.greendao}",
                rxjava         : "io.reactivex.rxjava2:rxjava:${depsVersion.rxjava}",
                rxandroid      : "io.reactivex.rxjava2:rxandroid:${depsVersion.rxandroid}",
                arouterapi     : "com.alibaba:arouter-api:${depsVersion.arouterapi}",
                aroutercompiler: "com.alibaba:arouter-compiler:${depsVersion.aroutercompiler}",
                magicindicator : "com.github.hackware1993:MagicIndicator:${depsVersion.magicindicator}",
                glide          : "com.github.bumptech.glide:glide:${depsVersion.glide}",
                glidecompiler  : "com.github.bumptech.glide:compiler:${depsVersion.glidecompiler}",
                okhttp         : "com.squareup.okhttp3:okhttp:${depsVersion.okhttp}",
                gson           : "com.google.code.gson:gson:${depsVersion.gson}",
    ]
}
100.png

引入根工程

//引入根工程下的统一版本管理文件
apply from: this.rootProject.file('imooc.gradle')

buildscript {
    repositories {
        jcenter()
        google()
        mavenCentral()
        maven {
            url 'http://localhost:8081/repository/imooc-releases/'
            credentials {
                username 'admin'
                password 'admin123'
            }
        }
        maven {
            url 'http://localhost:8081/repository/imooc-snapshots/'
            credentials {
                username 'admin'
                password 'admin123'
            }
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        //greendao插件依赖
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
        //ARouter插件依赖
        classpath "com.alibaba:arouter-register:1.0.2"
    }
}

allprojects {
    repositories {
        jcenter()
        google()
        maven { url "https://jitpack.io" }
        //项目自己的仓库
        maven {
            url 'http://localhost:8081/repository/imooc-releases/'
            credentials {
                username 'admin'
                password 'admin123'
            }
        }
        maven {
            url 'http://localhost:8081/repository/imooc-snapshots/'
            credentials {
                username 'admin'
                password 'admin123'
            }
        }
    }
}

在宿主以及其它modul的build.gradle使用

apply plugin: 'com.android.application'
apply plugin: 'com.alibaba.arouter'

android {
    compileSdkVersion rootProject.android.compileSdkVersion
    buildToolsVersion rootProject.android.buildToolsVersion


    defaultConfig {
        applicationId rootProject.android.applicationId
        minSdkVersion rootProject.android.minSdkVersion
        targetSdkVersion rootProject.android.targetSdkVersion
        versionCode rootProject.android.versionCode
        versionName rootProject.android.versionName
        multiDexEnabled rootProject.android.multiDexEnabled

        //ARouter配置
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [AROUTER_MODULE_NAME: project.getName(), AROUTER_GENERATE_DOC: "enable"]
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    lintOptions {
        abortOnError false
    }

    //不同渠道的签名,可以定义多个
    signingConfigs {
        release {
            // 绝对路径或相对路径
            storeFile file("imooc_voice_key")
            storePassword "123456"
            keyAlias "qndroid"
            keyPassword "123456"
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation rootProject.depsLibs.appcompact
    implementation rootProject.depsLibs.design
    implementation rootProject.depsLibs.recyclerview
    implementation rootProject.depsLibs.constraint
    //eventbus类库依赖
    implementation rootProject.depsLibs.eventbus
    //greendao类库依赖
    implementation rootProject.depsLibs.greendao
    //rxjava库
    implementation rootProject.depsLibs.rxjava
    implementation rootProject.depsLibs.rxandroid
    //arouter库
    implementation(rootProject.depsLibs.arouterapi) {
        exclude group: 'com.android.support'
    }
    annotationProcessor rootProject.depsLibs.aroutercompiler
    //gson解析库
    implementation rootProject.depsLibs.gson
    //基础UI库
    implementation project(':lib_commin_ui')
    //二维码扫描库
    implementation project(':lib_qrcode')
    //视频播放器组件
    implementation project(':lib_video')
    //音频播放器组
    implementation project(':lib_audio')
    //自己的maven库依赖
    //implementation 'com.imooc.android:lib_audio:1.0.0-SNAPSHOT'
    //webview库
    implementation project(':lib_webview')
    //网络请求库
    implementation project(':lib_network')
    //app下载更新库
    implementation project(':lib_update')
    //分享库
    implementation project(':lib_share')
    //图片加载库
    implementation project(':lib_image_loader')
    //保活库
    implementation project(':lib_pullalive')
    //业务基础库
    implementation project(':lib_base')
}

相关文章

网友评论

      本文标题:工程结构优化

      本文链接:https://www.haomeiwen.com/subject/hbomwctx.html