Merge remote-tracking branch 'origin/master'
# Conflicts: # app/build.gradle.kts # app/src/main/java/org/autojs/autojs/ui/error/ErrorDialogActivity.java
This commit is contained in:
@@ -250,6 +250,9 @@ dependencies /* Unclassified */ {
|
|||||||
// ICU4J
|
// ICU4J
|
||||||
implementation(libs.icu4j)
|
implementation(libs.icu4j)
|
||||||
|
|
||||||
|
// R8
|
||||||
|
implementation("com.android.tools:r8:8.13.17")
|
||||||
|
|
||||||
// Plugin API: Paddle OCR
|
// Plugin API: Paddle OCR
|
||||||
implementation(project(":plugin-api:paddle-ocr"))
|
implementation(project(":plugin-api:paddle-ocr"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package org.autojs.autojs.rhino
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.android.dx.command.dexer.Main
|
import com.android.dx.command.dexer.Main
|
||||||
|
import com.android.tools.r8.CompilationMode
|
||||||
|
import com.android.tools.r8.D8
|
||||||
|
import com.android.tools.r8.D8Command
|
||||||
|
import com.android.tools.r8.OutputMode
|
||||||
import dalvik.system.DexClassLoader
|
import dalvik.system.DexClassLoader
|
||||||
import net.lingala.zip4j.ZipFile
|
import net.lingala.zip4j.ZipFile
|
||||||
import net.lingala.zip4j.exception.ZipException
|
import net.lingala.zip4j.exception.ZipException
|
||||||
@@ -84,8 +88,18 @@ class AndroidClassLoader(private val parent: ClassLoader, private val cacheDir:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
|
||||||
fun loadJar(file: File): DexClassLoader {
|
fun loadJar(file: File): DexClassLoader {
|
||||||
|
try {
|
||||||
|
val dexFile = jarToDex(file, cacheDir)
|
||||||
|
return loadDex(dexFile)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "loadJar: failed to load jar ${file.path}", e)
|
||||||
|
return loadJar1(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun loadJar1(file: File): DexClassLoader {
|
||||||
val path = file.path
|
val path = file.path
|
||||||
Log.d(TAG, "loadJar: jar = $path")
|
Log.d(TAG, "loadJar: jar = $path")
|
||||||
if (!file.exists() || !file.canRead()) {
|
if (!file.exists() || !file.canRead()) {
|
||||||
@@ -215,6 +229,39 @@ class AndroidClassLoader(private val parent: ClassLoader, private val cacheDir:
|
|||||||
|
|
||||||
private fun generateDexFileName(jar: File) = md5("${jar.path}_${jar.lastModified()}")
|
private fun generateDexFileName(jar: File) = md5("${jar.path}_${jar.lastModified()}")
|
||||||
|
|
||||||
|
private fun jarToDex(jar: File, cacheDir: File): File {
|
||||||
|
val dexName = generateDexFileName(jar)
|
||||||
|
val dexFile = File(cacheDir, "$dexName.dex")
|
||||||
|
if (dexFile.exists()) {
|
||||||
|
return dexFile
|
||||||
|
}
|
||||||
|
val tmpOut = File(cacheDir, "${dexName}_tmp").apply { mkdirs() }
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val cmd = D8Command.builder()
|
||||||
|
.addProgramFiles(jar.toPath())
|
||||||
|
.setOutput(tmpOut.toPath(), OutputMode.DexIndexed)
|
||||||
|
.setMode(CompilationMode.RELEASE)
|
||||||
|
.build()
|
||||||
|
D8.run(cmd)
|
||||||
|
} else {
|
||||||
|
val args = arrayOf(
|
||||||
|
"--output", tmpOut.absolutePath,
|
||||||
|
"--release",
|
||||||
|
jar.absolutePath
|
||||||
|
)
|
||||||
|
D8.main(args)
|
||||||
|
}
|
||||||
|
val classesDex = File(tmpOut, "classes.dex")
|
||||||
|
if (classesDex.exists().not()) {
|
||||||
|
throw IOException("R8 did not produce classes.dex")
|
||||||
|
}
|
||||||
|
if (classesDex.renameTo(dexFile).not()) {
|
||||||
|
dexFile.outputStream().use { out -> classesDex.inputStream().use { it.copyTo(out) } }
|
||||||
|
}
|
||||||
|
tmpOut.deleteRecursively()
|
||||||
|
return dexFile
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val TAG = AndroidClassLoader::class.java.simpleName
|
private val TAG = AndroidClassLoader::class.java.simpleName
|
||||||
|
|||||||
Reference in New Issue
Block a user