Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打包功能优化 #187

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
/build
/app
/inrt
21 changes: 6 additions & 15 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ dependencies /* MLKit */ {
implementation("com.google.mlkit:barcode-scanning:17.2.0")
}

dependencies /* openCC */ {
// openCC
implementation("com.github.qichuan:android-opencc:1.2.0")
}

dependencies /* Auto.js Extensions */ {
// Settings Compat
// @Integrated by SuperMonster003 on Mar 30, 2023.
Expand Down Expand Up @@ -361,6 +366,7 @@ android {
"icon" to "@mipmap/ic_launcher",
)
)
ndk.abiFilters.addAll(listOf("")) // No ABI files is needed.

gradle.taskGraph.whenReady(object : Action<TaskExecutionGraph> {
override fun execute(taskGraph: TaskExecutionGraph) {
Expand Down Expand Up @@ -409,21 +415,6 @@ android {

}

sourceSets {
// @Hint by LZX284 on Nov 15, 2023.
// ! The assets file is divided into three directories according to different flavors.
// ! But the files are not actually moved to avoid conflicts with the latest modifications.
getByName("main"){
assets.srcDirs("src/main/assets")
}
getByName(flavorNameApp){
assets.srcDirs("src/main/assets_$flavorNameApp")
}
getByName(flavorNameInrt){
assets.srcDirs("src/main/assets_$flavorNameInrt")
}
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = versions.javaVersion
Expand Down
35 changes: 31 additions & 4 deletions app/src/main/java/org/autojs/autojs/apkbuilder/ApkBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ open class ApkBuilder(apkInputStream: InputStream?, private val mOutApkFile: Fil
File(mWorkspacePath).mkdirs()
mApkPackager.unzip()
copyAssetsRecursively("", File(mWorkspacePath, "assets"))
copyLibDir()
}

private fun copyLibDir() {
val srcLibDir = File(GlobalAppContext.get().packageManager.getApplicationInfo(GlobalAppContext.get().packageName,0).sourceDir).parent!!.plus("/lib")
val subDirs = File(srcLibDir).listFiles { file -> file.isDirectory }?.toList() ?: emptyList()
val abiMap = mapOf(
"x86_64" to "x86_64",
"x86" to "x86",
"arm64-v8a" to "arm64-v8a",
"armeabi-v7a" to "armeabi-v7a",
"arm64" to "arm64-v8a",
"arm" to "armeabi-v7a"
)
for ((key,value ) in abiMap){
subDirs.forEach {subDir->
when(subDir.name.lowercase()==key){
true -> {
File(srcLibDir, subDir.name).copyRecursively(File(mWorkspacePath,"lib/$value"),false)
}
else -> {}
}
}
}
}

@Throws(IOException::class)
Expand Down Expand Up @@ -185,11 +209,14 @@ open class ApkBuilder(apkInputStream: InputStream?, private val mOutApkFile: Fil
private fun copyAssetsRecursively(assetPath: String, targetFile: File) {
if (targetFile.isFile && targetFile.exists()) return
val list = mAssetManager.list(assetPath) ?: return
val unneededFiles = listOf("template.apk")
if (list.isEmpty()) /* asset is file */ {
mAssetManager.open(assetPath).use { input ->
FileOutputStream(targetFile.absolutePath).use { output ->
input.copyTo(output)
output.flush()
if (!unneededFiles.contains(targetFile.name.lowercase())){
mAssetManager.open(assetPath).use { input ->
FileOutputStream(targetFile.absolutePath).use { output ->
input.copyTo(output)
output.flush()
}
}
}
} else /* asset is folder */ {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/org/autojs/autojs/runtime/api/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,12 @@ class AppUtils {
}

@JvmStatic
fun isBroadcastShortForm(s: String) = BroadcastShortForm.entries.any { it.shortName.contentEquals(s) }
// fun isBroadcastShortForm(s: String) = BroadcastShortForm.entries.any { it.shortName.contentEquals(s) }
fun isBroadcastShortForm(s: String) = BroadcastShortForm.values().any { it.shortName.contentEquals(s) }

@JvmStatic
fun isActivityShortForm(s: String) = ActivityShortForm.entries.any { it.shortName.contentEquals(s) }
// fun isActivityShortForm(s: String) = ActivityShortForm.entries.any { it.shortName.contentEquals(s) }
fun isActivityShortForm(s: String) = ActivityShortForm.values().any { it.shortName.contentEquals(s) }

fun getInstalledApplications(context: Context): List<ApplicationInfo> = context.packageManager.let {
when {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/autojs/autojs/runtime/api/Floaty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import org.autojs.autojs.ui.enhancedfloaty.FloatyService
import org.autojs.autojs.util.ViewUtils.setViewMeasure
import org.autojs.autojs6.R
import java.util.concurrent.CopyOnWriteArraySet
import kotlin.concurrent.Volatile
//import kotlin.concurrent.Volatile
import kotlin.jvm.Volatile

/**
* Created by Stardust on 2017/12/5.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class AppLanguagePreference : MaterialListPreference {

override fun onChangeConfirmed(dialog: MaterialDialog) {
super.onChangeConfirmed(dialog)
Language.entries.find {
// Language.entries.find {
Language.values().find {
it.getEntryName(prefContext) == dialog.items?.get(dialog.selectedIndex)
}?.let {
GlobalAppContext.post {
Expand Down