Gradle8.x语法变动

385 阅读1分钟

maven仓库

之前

maven { url 'https://maven.aliyun.com/repository/public' } 使用以上方式在8.x环境build时会报错#### Unexpected tokens (use ';' to separate expressions on the same line)

之后

maven("https://maven.aliyun.com/repository/public")

maven { url = uri("https://maven.aliyun.com/repository/public") }

如下所示

repositories {
    maven("https://maven.aliyun.com/repository/public")
    maven("https://maven.aliyun.com/repository/central")
    maven("https://maven.aliyun.com/repository/jcenter")
    maven("https://maven.aliyun.com/repository/google") {
        content {
            includeGroupByRegex("com\\.android.*")
            includeGroupByRegex("com\\.google.*")
            includeGroupByRegex("androidx.*")
        }
    }
    google {
        content {
            includeGroupByRegex("com\\.android.*")
            includeGroupByRegex("com\\.google.*")
            includeGroupByRegex("androidx.*")
        }
    }
	// 保留默认的maven镜像,避免上述镜像中找不到包的下载地址
    mavenCentral()
    gradlePluginPortal()
}

NDK配置

之前

image.png

之后

使用 abiFilters.add("xxx")

defaultConfig {
    //...
    ndk {
        abiFilters.add("armeabi-v7a")
        abiFilters.add("arm64-v8a")
        abiFilters.add("x86_64")
    }
}

签名文件配置与使用

android {
    //签名文件配置,名字可自定义,如"release"
    signingConfigs {
        create("release") {
            storeFile = file("/Users/pc/code/android/android_test/test.jks")
            storePassword = "qwe123"
            keyAlias = "test"
            keyPassword = "qwe123"
        }
    }
   
   
    buildTypes {
        release {
            isMinifyEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            //打包变体饮用签名文件
            signingConfig = signingConfigs.getByName("release")
        }
    }
}

持续更新中...