Skip to content

Commit

Permalink
修复打包的一些BUG(自定义签名BUG未修复)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilinz committed Aug 19, 2022
1 parent 9fa559b commit 37762e5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 46 deletions.
11 changes: 6 additions & 5 deletions app/src/main/java/org/autojs/autojs/build/ApkBuilder.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.autojs.autojs.build

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.Log
import androidx.core.net.toUri
import com.stardust.app.GlobalAppContext
import com.stardust.autojs.apkbuilder.ApkPackager
import com.stardust.autojs.apkbuilder.ManifestEditor
import com.stardust.pio.copyToAndClose
import com.stardust.autojs.project.BuildInfo
import com.stardust.autojs.project.ProjectConfig
import com.stardust.autojs.script.EncryptedScriptFileHeader
Expand Down Expand Up @@ -105,12 +102,16 @@ class ApkBuilder(
ignoredPath: List<String> = projectConfig!!.ignoredDirs,
ignoredName: List<String> = emptyList()
) {
val ignoredPath1 = ignoredPath.map {
if (it.startsWith("/")) it
else PFiles.join(projectConfig!!.projectDirectory!!, it)
}
val fromDir = File(srcPath)
val toDir = File(workspacePath, relativeTargetPath)
toDir.mkdirs()
val children = fromDir.listFiles() ?: return
for (child in children) {
val ignored = ignoredPath.contains(child.path) || ignoredName.contains(child.name)
val ignored = ignoredPath1.any { child.path.startsWith(it) } || ignoredName.contains(child.name)
if (ignored) continue
if (child.isFile) {
if (child.name.endsWith(".js")) {
Expand Down Expand Up @@ -188,7 +189,7 @@ class ApkBuilder(
srcPath = file.path,
relativeTargetPath = relativeTo.path,
ignoredPath = listOf(
File(projectConfig!!.projectDirectory, ProjectConfig.CONFIG_FILE_NAME).path,
ProjectConfig.CONFIG_FILE_NAME,
projectConfig!!.sourcePath!!
)
)
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/org/autojs/autojs/build/DefaultSign.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.autojs.autojs.build

import android.util.Base64
import com.stardust.pio.PFiles
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import java.io.*
Expand Down Expand Up @@ -117,9 +118,10 @@ object DefaultSign {

@Throws(Exception::class)
fun sign(dir: File, out: OutputStream) {
File(dir, "META-INF").listFiles()?.forEach {
if (it.extension.matches(Regex("MF|SF|RSA"))) it.delete()
}
val zos = ZipOutputStream(out)
zos.putNextEntry(ZipEntry("META-INF/"))
zos.closeEntry()
val manifest = Manifest()
val sha1Manifest = writeMF(dir, manifest, zos)
val sf = generateSF(manifest)
Expand Down Expand Up @@ -171,9 +173,11 @@ object DefaultSign {

@Throws(NoSuchAlgorithmException::class, IOException::class)
private fun zipAndSha1(dir: File, zos: ZipOutputStream, dos: DigestOutputStream, m: Manifest) {
val children = dir.listFiles()?:return
val metaDir = File(dir, "META-INF")
if (!metaDir.exists()) metaDir.mkdirs()
val children = dir.listFiles() ?: return
for (element in children) {
if (!element.name.matches(Regex("^META-INF/(MANIFEST.MF|CERT.RSA|CERT.SF)$"))) {
if (!PFiles.getExtension(element.name).matches(Regex("MF|RSA|SF"))) {
if (element.isFile) {
doFile(element.name, element, zos, dos, m)
} else {
Expand Down
34 changes: 17 additions & 17 deletions app/src/main/java/org/autojs/autojs/ui/build/BuildPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -517,23 +517,23 @@ private fun FileCard(model: BuildViewModel) {
}
}

Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
MyTextField(
value = model.customOcrModelPath,
onValueChange = { model.customOcrModelPath = it },
label = { Text(text = stringResource(id = R.string.text_custom_ocr_model_path)) },
modifier = Modifier.weight(1f),
)
TextButton(onClick = {
selectCustomOcrModelPath(
context = context,
scriptPath = model.sourcePath,
onResult = { model.customOcrModelPath = it.absolutePath },
)
}) {
Text(text = stringResource(id = R.string.text_select))
}
}
// Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
// MyTextField(
// value = model.customOcrModelPath,
// onValueChange = { model.customOcrModelPath = it },
// label = { Text(text = stringResource(id = R.string.text_custom_ocr_model_path)) },
// modifier = Modifier.weight(1f),
// )
// TextButton(onClick = {
// selectCustomOcrModelPath(
// context = context,
// scriptPath = model.sourcePath,
// onResult = { model.customOcrModelPath = it.absolutePath },
// )
// }) {
// Text(text = stringResource(id = R.string.text_select))
// }
// }

}
}
Expand Down
48 changes: 28 additions & 20 deletions app/src/main/java/org/autojs/autojs/ui/build/BuildViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BuildViewModel(private val app: Application, private var source: String) :
//文件
var sourcePath by mutableStateOf("")
var outputPath by mutableStateOf("")
var customOcrModelPath by mutableStateOf("")
// var customOcrModelPath by mutableStateOf("")


//配置
Expand Down Expand Up @@ -251,6 +251,7 @@ class BuildViewModel(private val app: Application, private var source: String) :
assets = getAssets()
libs = getLibs()
abis = getAbiList().toMutableList()
if (ignoredDirs.isEmpty()) ignoredDirs = listOf(buildDir)
name = viewModel.appName
versionCode = viewModel.versionCode.toInt()
versionName = viewModel.versionName
Expand Down Expand Up @@ -329,15 +330,15 @@ class BuildViewModel(private val app: Application, private var source: String) :
)
)
}
if (customOcrModelPath.isNotBlank()) {
val dirName = File(customOcrModelPath).name
assetsList.add(
Asset(
form = customOcrModelPath,
to = "/${Constant.Assets.OCR_MODELS}/$dirName"
)
)
}
// if (customOcrModelPath.isNotBlank()) {
// val dirName = File(customOcrModelPath).name
// assetsList.add(
// Asset(
// form = customOcrModelPath,
// to = "/${Constant.Assets.OCR_MODELS}/$dirName"
// )
// )
// }
if (!isSingleFile) {
assetsList.add(
Asset(
Expand Down Expand Up @@ -389,9 +390,9 @@ class BuildViewModel(private val app: Application, private var source: String) :

private fun setAssets(projectConfig: ProjectConfig) {
projectConfig.assets.forEach {
if (it.to.startsWith("/${Constant.Assets.OCR_MODELS}/")) {
customOcrModelPath = it.form
}
// if (it.to.startsWith("/${Constant.Assets.OCR_MODELS}/")) {
// customOcrModelPath = it.form
// }
if (it.form == "${Constant.Protocol.ASSETS}/${Constant.Assets.OCR_MODELS}") {
isRequiredDefaultOcrModel = true
}
Expand Down Expand Up @@ -457,11 +458,6 @@ class BuildViewModel(private val app: Application, private var source: String) :
}

private fun setupWithSourceFile(file: ScriptFile) {
var dir: String = file.parent ?: ""
if (dir.startsWith(app.filesDir.path)) {
dir = Pref.getScriptDirPath() ?: ""
}
outputPath = dir
appName = file.simplifiedName
packageName = app.getString(
R.string.format_default_package_name,
Expand Down Expand Up @@ -496,9 +492,21 @@ class BuildViewModel(private val app: Application, private var source: String) :
sourcePath = File(directory!!, mainScript).path
}
syncViewModelByConfig(projectConfig)
}

setOutputPath()
}

private fun setOutputPath() {
oldProjectConfig?.outputPath?.let {
outputPath = it
} ?: kotlin.run {
outputPath = if (!isSingleFile) File(source, projectConfig.buildDir).path
else directory!!
var dir: String = if (isSingleFile) directory!!
else File(source, projectConfig.buildDir).path
if (dir.startsWith(app.filesDir.path)) {
dir = PFiles.join(Pref.getScriptDirPath(), "build")
}
outputPath = dir
}
}

Expand Down

0 comments on commit 37762e5

Please sign in to comment.