欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android studio 使用网络版本的gradle

程序员文章站 2022-05-02 19:05:09
...

说明

使用android studio使用网络办的gradle,直接通过git就可以

使用步骤

1. 创建一个工程,上传到github或gitee(码云)

2.使用raw源文件(github一直不能显示,这里用码云)

android studio 使用网络版本的gradle
android studio 使用网络版本的gradle

apply from使用

1. apply from './common.gradle'
2. apply from: 'https://gitee.com/WhatINeed/gradles/raw/master/common_androidx.gradle'

使用完整版代码

apply plugin: 'com.android.library'
apply from: 'https://gitee.com/WhatINeed/gradles/raw/master/common_androidx.gradle'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion project.ext.compileSdkVersion
    buildToolsVersion project.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion project.ext.minSdkVersion
        targetSdkVersion project.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }

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

    android {
        lintOptions {
            abortOnError false
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project.ext.deps.xappcompat
    implementation project.ext.deps.picasso
    implementation project.ext.deps.gson
    implementation project.ext.deps.okhttputils
    implementation project.ext.deps.systembartint //顶部的状态栏
    implementation project.ext.deps.jsoup //顶部的状态栏
    implementation project.ext.deps.rxjava2
    implementation project.ext.deps.recyclerview
    implementation project.ext.deps.core_ktx
    implementation project.ext.deps.kotlin_stdlib_jdk7
}
repositories {
    mavenCentral()
}

common_android.gradle源文件

//公共的配置文件,统一引用,提高编译以及以后架构的效率
def supportVersion = "29.+"
def retrofit2 = "2.6.2"
def kotlin_version = '1.3.50'
def glide_version = '4.9.0'

ext {
    minSdkVersion = 19
    targetSdkVersion = 29
    compileSdkVersion = 29
    buildToolsVersion = "29.0.2"
    sourceCompatibilityVersion = JavaVersion.VERSION_1_7
    targetCompatibilityVersion = JavaVersion.VERSION_1_7
    deps = [
            "constraintlayout"       : 'androidx.constraintlayout:constraintlayout:1.1.3',
            //"appcompat_v7"           : 'androidx.appcompat:appcompat:1.0.0',
            "xappcompat"             : "androidx.appcompat:appcompat:1.1.0",
            "core_ktx"               : "androidx.core:core-ktx:1.1.0",
            "kotlin_stdlib_jdk7"     : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version",
            "support_v4"             : 'androidx.legacy:legacy-support-v4:1.0.0',
            "design"                 : "com.android.support:design:${supportVersion}",
            "material"               : "com.google.android.material:material:1.0.0",
            "cardview_v7"            : "com.android.support:cardview-v7:${supportVersion}",
            "recyclerview"           : 'androidx.recyclerview:recyclerview:1.0.0',
            //retrofit相关↓
            "retrofit"               : "com.squareup.retrofit2:retrofit:${retrofit2}",
            "converter_gson"         : "com.squareup.retrofit2:converter-gson:${retrofit2}",
            "converter_scalars"      : "com.squareup.retrofit2:converter-scalars:${retrofit2}",
            "adapter_rxjava"         : "com.squareup.retrofit2:adapter-rxjava:${retrofit2}",
            "adapter_rxjava2"        : "com.squareup.retrofit2:adapter-rxjava2:${retrofit2}",
            "rxAndroid2"             : 'io.reactivex.rxjava2:rxandroid:2.1.1',
            "rxjava2"                : 'io.reactivex.rxjava2:rxjava:2.2.10',
            "rxkotlin"               : 'io.reactivex.rxjava2:rxkotlin:2.4.0',
            "okhttp"                 : 'com.squareup.okhttp3:okhttp:4.2.0',
            "okhttputils"            : 'com.zhy:okhttputils:2.6.2',
            "logging_interceptor"    : 'com.squareup.okhttp3:logging-interceptor:4.2.0',
            "butterknife"            : 'com.jakewharton:butterknife:8.8.1',
            "butterknife_compiler"   : "com.jakewharton:butterknife-compiler:8.8.1",
            "rxbinding"              : 'com.jakewharton.rxbinding3:rxbinding:3.0.0',
            "rxbinding_core"         : 'com.jakewharton.rxbinding3:rxbinding-core:3.0.0',
            "rxbinding_appcompat"    : 'com.jakewharton.rxbinding3:rxbinding-appcompat:3.0.0',
            "rxbinding_drawerlayout" : 'com.jakewharton.rxbinding3:rxbinding-drawerlayout:3.0.0',
            "rxbinding_leanback"     : 'com.jakewharton.rxbinding3:rxbinding-leanback:3.0.0',
            "rxbinding_recyclerview" : 'com.jakewharton.rxbinding3:rxbinding-recyclerview:3.0.0',
            "rxbinding_slidingpanelayout": 'com.jakewharton.rxbinding3:rxbinding-slidingpanelayout:3.0.0',
            "rxbinding_swiperefreshlayout": 'com.jakewharton.rxbinding3:rxbinding-swiperefreshlayout:3.0.0',
            "rxbinding_viewpager"    : 'com.jakewharton.rxbinding3:rxbinding-viewpager:3.0.0',
            "Java_WebSocket"         : 'org.java-websocket:Java-WebSocket:1.3.0',
            "picasso"                : 'com.squareup.picasso:picasso:2.5.2',
            "greendao"               : 'org.greenrobot:greendao:3.2.0',
            "appUpdate"              : 'com.readboy.lee.AppUpdate:appUpdate:3.0.6',
            "gson"                   : "com.google.code.gson:gson:2.8.0",
            "fastjson"               : "com.alibaba:fastjson:1.2.16",
            "keyboardvisibilityevent": "net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.0.0",
            "tagsoup"                : "org.ccil.cowan.tagsoup:tagsoup:1.2.1",
            "logger"                 : "com.orhanobut:logger:2.2.0",
            "matisse"                : "com.zhihu.android:matisse:0.5.1",
            "flowlayout"             : "com.hyman:flowlayout-lib:1.1.2",
            "glide"                  : "com.github.bumptech.glide:glide:${glide_version}",
            "glideannotation"        : "com.github.bumptech.glide:compiler:${glide_version}",
            "tablayout"              : "com.flyco.tablayout:FlycoTabLayout_Lib:aaa@qq.com",
            //test
            "test_junit"             : "junit:junit:4.12",
            "roundedimageview"       : "com.makeramen:roundedimageview:2.2.1",
            "jsoup"                  : "org.jsoup:jsoup:1.11.3",
            //公司自己的
            "sainttree"              : "com.tpddns.flannery.sainttree:sainttree:0.0.1", //目录树
            //"UseTime"                : "com.istarshine.usetimestatistic:UseTime:0.0.1"
            "systembartint"          : "com.readystatesoftware.systembartint:systembartint:1.0.3", //顶部statusbar
            "rippleeffect"           : "com.github.traex.rippleeffect:library:1.3", //水波纹效果
//            "tokenautocomplete"      : "com.splitwise:tokenautocomplete:aaa@qq.com"
            "jiecaovideoplayer"      :"com.github.open-android:JieCaoVideoPlayer:0.1.0"
//            "androidautosize"        : "me.jessyan:autosize:1.1.2"  //屏幕适配
    ]
}

配置版本号

    compileSdkVersion project.ext.compileSdkVersion
    buildToolsVersion project.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion project.ext.minSdkVersion
        targetSdkVersion project.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }

使用依赖

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project.ext.deps.xappcompat
    implementation project.ext.deps.picasso
    implementation project.ext.deps.gson
    implementation project.ext.deps.okhttputils
    implementation project.ext.deps.systembartint //顶部的状态栏
    implementation project.ext.deps.jsoup //顶部的状态栏
    implementation project.ext.deps.rxjava2
    implementation project.ext.deps.recyclerview
    implementation project.ext.deps.core_ktx
    implementation project.ext.deps.kotlin_stdlib_jdk7
}