美文网首页
Android 工程默认gradle配置

Android 工程默认gradle配置

作者: 放羊娃华振 | 来源:发表于2022-10-13 13:02 被阅读0次

一、settings.gradle

//rootProject.name = "MyApplication2"
include ':app'

二、gradle.properties

android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

三、工程根目录下的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.3.50'

    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/public' }

    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}


allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/public' }

    }

    ext {
        compileSdkVersion = 30
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        targetSdkVersion = 30

        versionCode = 1 //版本号
        versionName = "1.0.0" //版本名称
    }
}

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

四、App目录下的build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "com.stormdzh.firebase.myapplication2"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion

        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        ndk {
            // 设置支持的SO库架构
            abiFilters 'armeabi-v7a'
        }

        //添加如下配置就OK了
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath = true
            }
        }

        multiDexEnabled true

    }

    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 fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

相关文章

网友评论

      本文标题:Android 工程默认gradle配置

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