-
Notifications
You must be signed in to change notification settings - Fork 107
/
build.gradle
176 lines (164 loc) · 6.21 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Copyright (c) 2021 FakeXposed by sanfengAndroid.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// Top-level build file where you can add configuration options common to all sub-projects/modules.
static String getType(List allAbi) {
def type = 0
type |= allAbi.contains('x86') ? 1 : 0
type |= allAbi.contains('x86_64') ? 1 : 0
type |= allAbi.contains('armeabi-v7a') ? 2 : 0
type |= allAbi.contains('arm64-v8a') ? 2 : 0
return type == 1 ? 'x86' : type == 2 ? 'arm' : 'all'
}
ext {
def props = new Properties()
if (project.hasProperty('configPath')) {
props.load(new FileInputStream(configPath))
} else if (project.file('local.properties').exists()) {
props.load(new FileInputStream(project.file('local.properties')))
}
mergeBuild = project.findProperty('mergeBuild')?.toBoolean()
if (mergeBuild == null) {
mergeBuild = props.getOrDefault('mergeBuild', true).toBoolean()
}
abis = project.findProperty('abis') ?: props.getOrDefault('abis', 'armeabi-v7a,x86,arm64-v8a,x86_64')
abis = abis?.trim()?.split(',')?.toList()
logLevel = project.findProperty('logLevel')?.toInteger() ?: props.getOrDefault('logLevel', 3).toInteger()
targetSdk = project.findProperty('targetSdk')?.toInteger() ?: props.getOrDefault('targetSdk', 34).toInteger()
emulatorBuild = project.findProperty('emulatorBuild')?.toBoolean()
if (emulatorBuild == null) {
emulatorBuild = props.getOrDefault('emulatorBuild', false).toBoolean()
}
storeFile = project.findProperty('storeFile')?.trim() ?: props.getProperty('storeFile')?.trim()
storePassword = project.findProperty('storePassword')?.trim() ?: props.getProperty('storePassword')?.trim()
keyAlias = project.findProperty('keyAlias')?.trim() ?: props.getProperty('keyAlias')?.trim()
keyPassword = project.findProperty('keyPassword')?.trim() ?: props.getProperty('keyPassword')?.trim()
hasSign = storeFile && storePassword && keyAlias && keyPassword
appType = getType(abis)
if (emulatorBuild) {
appType = 'arm'
}
assert (targetSdk >= 21)
fakeLinkerModuleName = project.findProperty('fakeLinkerModuleName')?.trim() ?: props.getOrDefault('fakeLinkerModuleName', 'fakelinker')?.trim()
installerModuleName = project.findProperty('installerModuleName')?.trim() ?: props.getOrDefault('installerModuleName', 'linkerInstaller')?.trim()
versionCode = project.findProperty('versionCode')?.toInteger() ?: props.getOrDefault('versionCode', 3100).
toInteger()
versionName = project.findProperty('versionName')?.trim() ?: props.getOrDefault('versionName', '3.1').trim()
}
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.4.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
/**
* 复制库文件到指定abi目录下
* @param input 具体的 lib/arm64-v8a/libfake-linker.so
* @param name 文件名称过滤
* @param abi 其它abi如 armeabi-v7a
*/
def copyLibraryFile(File input, String name, String abi) {
if (input.name != "lib${name}.so") {
return
}
if (!input.exists()) {
return
}
def abiDir = new File(input.parentFile.parentFile, abi)
if (abiDir.exists()) {
copy {
from input
into abiDir
}
}
}
/**
* 在打包64位app时将32位库也安装到64位库目录,这样在64位手机上安装会提取64位库和32位库,
* 在32位手机上安装则只有32位库
* @param outputs
* @return
*/
def merge32BitTo64BitLibrary(FileCollection outputs, String moduleName) {
if (!mergeBuild) {
return
}
println 'Merge build mode, the 32-bit library will be copied to the 64-bit directory'
outputs.files.each { File dir ->
dir.eachFileRecurse {
if (it.parentFile.name == 'armeabi-v7a' || it.parentFile.name == 'armeabi') {
copyLibraryFile(it, "${moduleName}32", 'arm64-v8a')
} else if (it.parentFile.name == 'x86') {
copyLibraryFile(it, "${moduleName}32", 'x86_64')
}
}
}
}
def reducedLibrary(FileCollection outputs) {
if (appType == 'all') {
return
}
def dirs = []
outputs.files.each { File dir ->
dir.eachDirRecurse {
if (appType == 'x86' && it.name in ['armeabi-v7a', 'arm64-v8a', 'armeabi']) {
dirs.add(it)
} else if (appType == 'arm' && it.name in ['x86', 'x86_64']) {
dirs.add(it)
}
}
}
for (dir in dirs) {
dir.deleteDir()
}
}
def emulatorBuildMoveLibrary(FileCollection outputs, String module) {
if (!emulatorBuild) {
return
}
println 'Emulator mode build, x86 library will be replaced by arm library'
def dirs = []
outputs.files.each { File dir ->
dir.eachDirRecurse {
// 模拟器下hook模块和fakelinker需要x86,其它的正常arm库
if (it.name == 'x86') {
copyLibraryFile(new File(it, "lib${module}32.so"), "${module}32", 'armeabi-v7a')
dirs.add(it)
} else if (it.name == 'x86_64') {
copyLibraryFile(new File(it, "lib${module}64.so"), "${module}64", 'arm64-v8a')
copyLibraryFile(new File(it, "lib${module}32.so"), "${module}32", 'arm64-v8a')
dirs.add(it)
}
}
}
for (d in dirs) {
d.deleteDir()
}
}