DEV_USER = “csp”
则 build.gradle 中直接使用
buildConfigField “String”, “DEV_USER”, DEV_USER
1.2. 引入其他 gradle 文件
两种方式
apply from: “${rootDir.path}/gradle/dependencies.gradle” // 方式一
apply from: rootProject.file(‘gradle/dependencies.gradle’) // 方式二
阿里云仓库添加
添加内容:根目录/build.gradle
buildscript {
repositories {
maven { url(“https://maven.aliyun.com/repository/public”) } // central 仓和 jcenter 仓的聚合仓
maven { url(“https://maven.aliyun.com/repository/google”) }
maven { url(“https://maven.aliyun.com/repository/gradle-plugin”) }
google()
jcenter()
}
}
allprojects {
repositories {
maven { url(“https://maven.aliyun.com/repository/public”) } // central 仓和 jcenter 仓的聚合仓
maven { url(“https://maven.aliyun.com/repository/google”) }
maven { url(“https://maven.aliyun.com/repository/gradle-plugin”) }
google()
jcenter()
}
}
添加单元测试 junit
这个默认就有了,这里记录一下
添加文件:项目目录/build.gradle
android {
defaultConfig {
testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner”
}
}
dependencies {
// 单元测试
testImplementation ‘junit:junit:4.13.1’
androidTestImplementation ‘androidx.test.ext:junit:1.1.2’
androidTestImplementation ‘androidx.test.espresso:espresso-core:3.3.0’
}
java 8
android {
// java 1.8
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
sourceSets
android {
// sourceSets
sourceSets {
main {
jniLibs.srcDirs ‘libs’
println “\nsourceSets 配置情况:”
sourceSets.all { set ->
println “[${set.name}]的文件是 ${set.java.srcDirs}”
}
}
}
}
自动签名
生成签名文件
- Build -> Generate Signed Bundle / APK
- Next -> Create new…
- 填写路径,密码,别名,然后 OK,就生成好了
添加内容:项目目录/build.gradle
android {
// 自动签名
signingConfigs {
println “\n[${project.name}]项目签名配置开始”
// 加载配置文件
String propertiesPath = “${rootDir.path}/keystore/keystore.properties”
File propertiesFile = file(propertiesPath)
// File propertiesFile = project.rootProject.file(‘keystore/keystore.properties’)
Properties properties = new Properties()
properties.load(propertiesFile.newDataInputStream())
// 配置自动签名
release {
storeFile file(properties[‘KEY_APP_STORE_FILE’])
// storeFile file(properties.getProperty(“KEY_APP_STORE_FILE”))
storePassword properties[‘KEY_STORE_PASSWORD’]
keyAlias properties[‘KEY_ALIAS’]
keyPassword properties[‘KEY_PASSWORD’]
}
println “签名配置文件路径