关于Android gradle 7.0+版本的配置升级 使用案例

1.关于settings.gradle的变化

原来的 

include ':app'
include ':marqueeview'

7.0+以后

pluginManagement {
    repositories {
        gradlePluginPortal()
        //华为maven
        maven {
            url "http://developer.huawei.com/repo/"
            allowInsecureProtocol = true
        }
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
            allowInsecureProtocol = true
        }
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
            allowInsecureProtocol = true
        }
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/google'
            allowInsecureProtocol = true
        }
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
            allowInsecureProtocol = true
        }
        google()
        mavenCentral()
        //noinspection JcenterRepositoryObsolete
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        //华为maven
        maven {
            url "http://developer.huawei.com/repo/"
            allowInsecureProtocol = true
        }
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
            allowInsecureProtocol = true
        }
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
            allowInsecureProtocol = true
        }
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/google'
            allowInsecureProtocol = true
        }
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
            allowInsecureProtocol = true
        }
        maven { url "https://jitpack.io" }
        google()
        mavenCentral()
        jcenter()
    }
}

rootProject.name = "MvvmKotlinProject"
include ':LocalPackage:AutoSize_aar'
include ':LocalPackage:Banner_aar'
include ':LocalPackage:LoadSir_aar'
include ':LocalPackage:CircleImageView_aar'
include ':LocalPackage:ImmersionBar_aar'
include ':LocalPackage:ImmersionBar_Components_aar'
include ':LocalPackage:ImmersionBar_Ktx_aar'
include ':LocalPackage:SuperTextView_aar'

enableFeaturePreview('VERSION_CATALOGS')
dependencyResolutionManagement {
    versionCatalogs {
        libs {
            from(files("libs.versions.toml"))
        }
    }
}
include ':app'
include ':marqueeview'

2.关于项目的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
        classpath "com.alibaba:arouter-register:1.0.2"
    }
}
plugins {
    id 'com.android.application' version '7.3.0' apply false
    id 'com.android.library' version '7.3.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.6.21' apply false
}

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

3.app或者module内的build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'version-catalog'
    id 'com.jakewharton.butterknife'
}

android {
    namespace 'it.dongjun.yigui'
    compileSdk libs.versions.compilesdk.get().toInteger()

    defaultConfig {
        applicationId "it.dongjun.yigui"
        minSdk libs.versions.minsdk.get().toInteger()
        targetSdk libs.versions.targetsdk.get().toInteger()
        versionCode libs.versions.versioncode.get().toInteger()
        versionName libs.versions.versionname.get().toString()

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

   task makeJar(type: Copy) {
        delete 'build/outputs/baselibrary.jar'
        from('build/intermediates/compile_library_classes_jar/release') //jar文件来源
        into('build/outputs/') //生成路径
        include('classes.jar')
        rename('classes.jar', 'baselibrary.jar')//mylibrary.jar  生成jar包的名称
    }
    makeJar.dependsOn(build)
}

catalog {
    versionCatalog {
        from files('../libs.versions.toml')
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

4.加上版本统一管理libs.versions.toml的使用和配置

# [versions] 部分用于声明可以被依赖项引用的版本
# [libraries] 部分用于声明 Library 的别名
# [bundles] 部分用于声明依赖包
# [plugins] 部分用于声明插件

[versions]
# android defaultConfig
minsdk = "21"
targetsdk = "32"
compilesdk = "32"
versioncode = "101"
versionname = "1.0.2"

# SDK
kotlin = "1.6.10"
lifecycle = "2.4.0"
retrofit = "2.9.0"
glide = "4.13.2"
room = "2.4.2"
picker = "4.1.9"

[libraries]
# androidX
core-ktx = "androidx.core:core-ktx:1.7.0"
appcompat = "androidx.appcompat:appcompat:1.3.1"
material = "com.google.android.material:material:1.4.0"
fragment = "androidx.fragment:fragment-ktx:1.4.0"
constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.1"
recyclerview = "androidx.recyclerview:recyclerview:1.2.1"
cardview = "androidx.cardview:cardview:1.0.0"

# lifecycle 生命周期管理
lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle" }
lifecycle-livedata = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "lifecycle" }
lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" }

# BaseRecyclerView
baserecyclerview = "com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.7"
# 腾讯 mmkv
mmkv = "com.tencent:mmkv:1.2.12"
utilcodex = "com.blankj:utilcodex:1.30.6"
# popup 弹窗
basepopup = "io.github.razerdp:BasePopup:3.2.0"
# permissionx
permissionx = "com.guolindev.permissionx:permissionx:1.6.4"
# 连点 防抖动
rxbinding = "com.jakewharton.rxbinding4:rxbinding:4.0.0"
# material-dialogs
commons-dialogs = "com.afollestad.material-dialogs:commons:0.9.6.0"
# splashscreen
splashscreen = "androidx.core:core-splashscreen:1.0.0-alpha02"
# PersistentCookieJar
persistent-cookie-jar = "com.github.franmontiel:PersistentCookieJar:v1.0.1"
# AgentWeb
agentWeb = "com.github.Justson.AgentWeb:agentweb-core:v5.0.0-alpha.1-androidx"
# okhttp 日志拦截器
logging-interceptor = "com.squareup.okhttp3:logging-interceptor:4.9.2"
# RxAndroid
rxandroid = "io.reactivex.rxjava3:rxandroid:3.0.0"
# multidex
multidex = "com.android.support:multidex:1.0.2"
# xcrash
xcrash = "com.iqiyi.xcrash:xcrash-android-lib:3.0.0"

#api 'me.yokeyword:fragmentationx:1.0.2'
#api 'com.kaopiz:kprogresshud:1.0.2'

# retrofit RxJava3 + retrofit2 + RxBinding。注意,RxBinding内包含RxJava2,所以不要再次引入RxJava2依赖
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" }
converter-scalars = { module = "com.squareup.retrofit2:converter-scalars", version.ref = "retrofit" }
adapter-rxjava3 = { module = "com.squareup.retrofit2:adapter-rxjava3", version.ref = "retrofit" }

# Glide 图片加载、缓存、转换
glide-core = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
glide-compiler = { module = "com.github.bumptech.glide:compiler", version.ref = "glide" }
#glide-transformations = "jp.wasabeef:glide-transformations:4.3.0"

# Room 数据库
room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
room-rxjava2 = { module = "androidx.room:room-rxjava2", version.ref = "room" }
room-rxjava3 = { module = "androidx.room:room-rxjava3", version.ref = "room" }
room-guava = { module = "androidx.room:room-guava", version.ref = "room" }
room-testing = { module = "androidx.room:room-testing", version.ref = "room" }
room-paging = "androidx.room:room-paging:2.5.0-alpha01" #Paging 3 Integration
roomkapt = { module = "androidx.room:room-compiler", version.ref = "room" }
#// To use Kotlin Symbolic Processing (KSP)
#ksp("androidx.room:room-compiler:$roomVersion")
#//界面管理
#'fragmentationx'          : "me.yokeyword:fragmentationx:1.0.2",
#'swipeback'               : "me.yokeyword:fragmentation-swipeback:1.3.7",

#androidPicker选择器类库
#androidpicker = "com.github.gzu-liyujiang.AndroidPicker:Common:4.1.9"
picker-common = { module = "com.github.gzu-liyujiang.AndroidPicker:Common", version.ref = "picker" }
picker-wheelview = { module = "com.github.gzu-liyujiang.AndroidPicker:WheelView", version.ref = "picker" }
picker-wheelPicker = { module = "com.github.gzu-liyujiang.AndroidPicker:WheelPicker", version.ref = "picker" }
picker-AddressPicker = { module = "com.github.gzu-liyujiang.AndroidPicker:AddressPicker", version.ref = "picker" }
picker-FilePicker = { module = "com.github.gzu-liyujiang.AndroidPicker:FilePicker", version.ref = "picker" }
picker-ColorPicker = { module = "com.github.gzu-liyujiang.AndroidPicker:ColorPicker", version.ref = "picker" }
picker-CalendarPicker = { module = "com.github.gzu-liyujiang.AndroidPicker:CalendarPicker", version.ref = "picker" }
picker-ImagePicker = { module = "com.github.gzu-liyujiang.AndroidPicker:ImagePicker", version.ref = "picker" }


[bundles]
glide = ["glide-core", "glide-compiler"]#, "glide-transformations"]
androidx = ["core-ktx", "appcompat", "material", "fragment", "constraintlayout", "recyclerview", "cardview"]
lifecycle = ["lifecycle-runtime", "lifecycle-livedata", "lifecycle-viewmodel"]
retrofit = ["retrofit", "converter-gson", "converter-scalars", "adapter-rxjava3"]
room = ["room-runtime", "room-compiler", "room-ktx", "room-rxjava2", "room-rxjava3", "room-guava", "room-testing"]
picker = ["picker-common", "picker-wheelview", "picker-wheelPicker"]

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Gradle 7.0是一个功能强大的构建工具,可以用于构建各种类型的项目。在Gradle 7.0中,可以使用AOP(面向对象编程)来增强应用程序的功能。 AOP是一种编程范式,它允许将横切关注点(即与核心业务逻辑无关的功能)从主要的业务逻辑中分离出来。通过使用AOP,我们可以在不修改源代码的情况下,以一种模块化的方式添加或移除额外的功能。 在Gradle 7.0中,我们可以通过引入相关的插件来使用AOP。一个常用的插件是AspectJ插件。使用AspectJ插件,我们可以在Gradle构建中使用AspectJ语法来定义切面和切点,然后将这些切面应用到我们的应用程序代码中。 要在Gradle 7.0使用AspectJ插件,我们需要在build.gradle文件中添加相应的配置。首先,需要添加AspectJ插件的依赖项。然后,我们需要配置AspectJ插件来将我们的切面编织到应用程序代码中。这可以通过在build.gradle文件中指定AspectJ插件的相关任务和设置来完成。 一旦AspectJ插件配置完成,我们就可以使用AspectJ语法来定义切面和切点。切面是横切关注点的实现,而切点是在应用程序代码中选择要应用切面的关注点的规则。 使用Gradle 7.0和AspectJ插件,我们可以很方便地在项目中应用AOP,从而增强应用程序的功能。无论是日志记录、异常处理还是性能监控,AOP都可以帮助我们更好地对应用程序进行管理和调试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值