-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
96 lines (87 loc) · 3.37 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
apply plugin: 'com.android.application'
//https://developer.android.google.cn/studio/projects/android-library
android {
namespace 'test.mxm.android_app_template'
compileSdk 33
defaultConfig {
applicationId "test.mxm.android_app_template"
minSdk 26
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk.abiFilters 'arm64-v8a','armeabi-v7a'//,'x86','x86_64'
//自定义打包名称,不完全自定义,后面自动会加上${buildType.name}
archivesBaseName = "Template_v${versionName}_${generateTime()}"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
//构建时间
def generateTime() {
return new Date().format("yyyy-MM-dd HH时mm分ss秒")
}
// 自定义打包名称,完全自定义
//android.applicationVariants.all { variant ->
// variant.outputs.all {
// outputFileName = "Template_${buildType.name}_v${versionName}_${generateTime()}.apk"
// }
//}
// 这个貌似必须放到 dependencies 之前,才能在 dependencies 中使用
def localGroup = 'test.mxm.local'
def localArtifactId = 'xxxAndroid'
def versionName = '1.0.0'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.7.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.squareup.okhttp3:okhttp:4.10.0-RC1'
// 引入本地库
// implementation "$localGroup:$localArtifactId:$versionName"
}
/*
把本地aar依赖库发布到本地 maven 源,以下代码必须放在 module 的 build.gradle 文件中,
否则 Android Studio 的 gradle 工具中看不到 publishing 任务,
双击 publishing 任务中的 publish 即可发布到本地,然后就可以看到 app 文件夹的平级文件夹 LocalMavenRepo
*/
apply plugin: 'maven-publish' // 发布到 maven 必须用的插件
def localMavenRepoUrl = '../LocalMavenRepo' // 项目本地源存放目录,
allprojects {
// 给当前 module 添加本地源,当前 module 非 app module 时,也要给 app module 添加此本地源,否则正式打包签名会报错
repositories {
maven { url localMavenRepoUrl }
}
}
publishing {
publications {
// 创建一个 Maven publication 任务叫 "myTask1".
myTask1(MavenPublication) {
groupId = localGroup
artifactId = localArtifactId
version = versionName
artifact 'libs/xxx.aar' // aar文件的路径
}
// myTask2(MavenPublication) {
// groupId = localGroup2
// artifactId = localArtifactId2
// version = versionName2
// artifact 'libs/xxx2.aar' // aar文件的路径
// }
}
repositories {
maven {
// 上传到项目本地仓库
url localMavenRepoUrl
}
}
}