Skip to content

Commit 5ee2f2f

Browse files
committed
fix(abi):fixed output
1 parent b7993b6 commit 5ee2f2f

File tree

2 files changed

+10
-28
lines changed

2 files changed

+10
-28
lines changed

android/app/build.gradle

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,34 +117,16 @@ android {
117117
}
118118

119119
import com.android.build.OutputFile
120+
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
120121

121-
androidComponents {
122-
onVariants(selector().all()) { variant ->
123-
def variantNameCap = variant.name.capitalize()
124-
def copyTask = tasks.register("copy${variantNameCap}Apk", Copy) {
125-
from(variant.artifacts.get(com.android.build.api.artifact.SingleArtifact.APK))
126-
into(layout.buildDirectory.dir("renamed-apks"))
127-
rename { fileName ->
128-
def abi = null
129-
// 获取 ABI 分包,仅在有时才返回非空
130-
variant.outputs.each { output ->
131-
def filterABI = output.getFilter(OutputFile.ABI)
132-
if (filterABI != null) { abi = filterABI }
133-
}
134-
def versionName = variant.versionName.get()
135-
return "OpenListF-v${versionName}${abi ? "_${abi}" : ""}.apk"
136-
}
137-
}
138-
139-
project.afterEvaluate {
140-
def assembleTask = tasks.named("assemble${variantNameCap}")
141-
assembleTask.configure {
142-
finalizedBy(copyTask)
143-
}
144-
copyTask.configure {
145-
dependsOn assembleTask
146-
}
147-
}
122+
android.applicationVariants.all { variant ->
123+
variant.outputs.each { output ->
124+
def abi = output.getFilter(OutputFile.ABI) // 对 universal APK 会返回 null
125+
def versionName = variant.versionName
126+
def fileName = "OpenListF-v${versionName}${abi ? "_${abi}" : ""}.apk"
127+
128+
def outputImpl = output as BaseVariantOutputImpl
129+
outputImpl.outputFileName = fileName
148130
}
149131
}
150132

0 commit comments

Comments
 (0)