Android gradle 7.0+完整配置记录

1.根目录 settings.gradle

pluginManagement {
    repositories {
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
            allowInsecureProtocol = true//这个是新增的
        }
        maven {
            url 'https://jitpack.io'
            allowInsecureProtocol = true
        }
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {

        //华为maven
        maven {
            url "http://developer.huawei.com/repo/"
            allowInsecureProtocol = true
        }
//        maven {
//            url "http://xxxxxxxx/repository/maven-public/"
//            allowInsecureProtocol = true
//        }
//        maven { url "https://jitpack.io" }

        google()
        mavenCentral()
    }
}
rootProject.name = "HiltDemo"
include ':app'

  2.根目录build.gradle

  

//注意 buildscript节点有可能没有 自己添加需要注意与plugins的顺序
buildscript {
    ext {
        kotlin_version = '1.6.10'
    }
    dependencies {
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.28-alpha'
    }
}
plugins {
    id 'com.android.application' version '7.1.1' apply false
    id 'com.android.library' version '7.1.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
//apply from: "config.gradle"//自定义配置清单还是能够使用
task clean(type: Delete) {
    delete rootProject.buildDir
}

  3.app或者module中的build.gradle

plugins {//这里的变化就是将apply plugin改为id
    id 'com.android.application'
//    apply plugin: 'kotlin-kapt'
//    apply plugin: 'dagger.hilt.android.plugin'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}
//apply from 'xxx.gradle'//可以正常使用


android {
    compileSdk 31

    defaultConfig {
        applicationId "com.tdroid.hiltdemo"
        minSdk 28
        targetSdk 31
        versionCode 1
        versionName "1.0"

        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
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation "com.google.dagger:hilt-android:2.28-alpha"
    kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
}

  顺便记录一个阿里云的 maven地址

https://maven.aliyun.com/repository/google

  

posted @ 2022-05-23 22:04  bg_不够  阅读(1990)  评论(0编辑  收藏  举报