Skip to content

Commit

Permalink
修复打包Bug && 优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wilinz committed Aug 20, 2022
1 parent 0f6a794 commit 81703d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
32 changes: 20 additions & 12 deletions app/src/main/java/org/autojs/autojs/build/ApkBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,31 @@ class ApkBuilder(
return this
}

private fun getAbsolutePath(name: String): String = projectConfig!!.getAbsolutePath(name)

fun copyDir(
srcPath: String,
relativeTargetPath: String,
ignoredPath: List<String> = projectConfig!!.ignoredDirs,
ignoredName: List<String> = emptyList()
ignoredPathList: List<String> = emptyList(),
) {
val ignoredPath1 = ignoredPath.map {
if (it.startsWith("/")) it
else PFiles.join(projectConfig!!.projectDirectory!!, it)
}
val ignoredPath1 = ignoredPathList.toMutableList()
.apply { addAll(projectConfig!!.ignoredDirs.map { getAbsolutePath(it) }) }
.map { path ->
if (File(path).isDirectory && !path.endsWith("/")) "$path/" else path
}

val fromDir = File(srcPath)
val toDir = File(workspacePath, relativeTargetPath)
toDir.mkdirs()
val children = fromDir.listFiles() ?: return

val children = fromDir.listFiles()
?.filter { file ->
!ignoredPath1.any {
(file.path.startsWith(it) || file.canonicalFile == File(it).canonicalFile)
}
} ?: return

for (child in children) {
val ignored = ignoredPath1.any { child.path.startsWith(it) } || ignoredName.contains(child.name)
if (ignored) continue
if (child.isFile) {
if (child.name.endsWith(".js")) {
encryptToDir(child, toDir)
Expand Down Expand Up @@ -188,9 +196,9 @@ class ApkBuilder(
copyDir(
srcPath = file.path,
relativeTargetPath = relativeTo.path,
ignoredPath = listOf(
ProjectConfig.CONFIG_FILE_NAME,
projectConfig!!.sourcePath!!
ignoredPathList = listOf(
getAbsolutePath(ProjectConfig.CONFIG_FILE_NAME),
getAbsolutePath(projectConfig!!.sourcePath!!)
)
)
return@forEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ data class ProjectConfig(
var assets: List<Asset> = emptyList(),
var signingConfig: SigningConfig = SigningConfig(),
) {

fun getAbsolutePath(name: String): String {
return if (name.startsWith("/")) name
else File(this.projectDirectory, name).absolutePath
}

companion object {

const val CONFIG_FILE_NAME = "project.json"
Expand Down Expand Up @@ -97,6 +103,7 @@ data class ProjectConfig(
fun configFileOfDir(projectDir: String, configName: String): String {
return PFiles.join(projectDir, configName)
}

}

fun toJson(): String {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/com/stardust/app/GlobalAppContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object GlobalAppContext {

fun set(a: Application, buildConfig: BuildConfig) {
this.buildConfig = buildConfig
Log.d(TAG, buildConfig.toString())
Log.i(TAG, buildConfig.toString())
sHandler = Handler(Looper.getMainLooper())
sApplicationContext = a.applicationContext
}
Expand Down

0 comments on commit 81703d2

Please sign in to comment.