6.6.2 - Alpha - 打包页面支持 Pinyin 库选项
This commit is contained in:
@@ -55,9 +55,9 @@ open class ApkBuilder(apkInputStream: InputStream?, private val outApkFile: File
|
||||
|
||||
private val mAssetManager: AssetManager by lazy { globalContext.assets }
|
||||
|
||||
private var mLibsIncludes = Libs.DEFALUT_INCLUDES.toMutableList()
|
||||
private var mAssetsFileIncludes = Assets.File.DEFAULT_INCLUDES.toMutableList()
|
||||
private var mAssetsDirExcludes = Assets.Dir.DEFAULT_EXCLUDES.toMutableList()
|
||||
private var mLibsIncludes = Libs.defaultLibsToInclude.toMutableList()
|
||||
private var mAssetsFileIncludes = Libs.defaultAssetFilesToInclude.toMutableList()
|
||||
private var mAssetsDirExcludes = Libs.defaultAssetDirsToExclude.toMutableList()
|
||||
|
||||
private val mManifestFile
|
||||
get() = File(workspacePath, "AndroidManifest.xml")
|
||||
@@ -184,29 +184,12 @@ open class ApkBuilder(apkInputStream: InputStream?, private val outApkFile: File
|
||||
projectConfig.run {
|
||||
mKey = MD5Utils.md5(packageName + versionName + mainScriptFile)
|
||||
mInitVector = MD5Utils.md5(buildInfo.buildId + name).substring(0, 16)
|
||||
if (appConfig.libs.contains(Constants.OPENCV)) {
|
||||
mLibsIncludes += Libs.OPENCV.toSet()
|
||||
mAssetsDirExcludes -= Assets.Dir.OPENCV.toSet()
|
||||
}
|
||||
if (appConfig.libs.contains(Constants.MLKIT_OCR)) {
|
||||
mLibsIncludes += Libs.MLKIT_GOOGLE_OCR.toSet()
|
||||
mAssetsDirExcludes -= Assets.Dir.MLKIT_GOOGLE_OCR.toSet()
|
||||
}
|
||||
if (appConfig.libs.contains(Constants.PADDLE_OCR)) {
|
||||
mLibsIncludes += Libs.PADDLE_LITE.toSet() + Libs.PADDLE_LITE_EXT.toSet()
|
||||
mAssetsDirExcludes -= Assets.Dir.PADDLE_LITE.toSet()
|
||||
}
|
||||
if (appConfig.libs.contains(Constants.MLKIT_BARCODE)) {
|
||||
mLibsIncludes += Libs.MLKIT_BARCODE.toSet()
|
||||
mAssetsDirExcludes -= Assets.Dir.MLKIT_BARCODE.toSet()
|
||||
}
|
||||
if (appConfig.libs.contains(Constants.RAPID_OCR)) {
|
||||
mLibsIncludes += Libs.RAPID_OCR.toSet()
|
||||
mAssetsDirExcludes -= Assets.Dir.RAPID_OCR.toSet()
|
||||
}
|
||||
if (appConfig.libs.contains(Constants.OPENCC)) {
|
||||
mLibsIncludes += Libs.OPENCC.toSet()
|
||||
mAssetsDirExcludes -= Assets.Dir.OPENCC.toSet()
|
||||
Libs.entries.forEach { entry ->
|
||||
if (appConfig.libs.contains(entry.label)) {
|
||||
mLibsIncludes += entry.libsToInclude.toSet()
|
||||
mAssetsFileIncludes += entry.assetFilesToInclude.toSet()
|
||||
mAssetsDirExcludes -= entry.assetDirsToExclude.toSet()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -478,119 +461,126 @@ open class ApkBuilder(apkInputStream: InputStream?, private val outApkFile: File
|
||||
|
||||
}
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
object Libs {
|
||||
enum class Libs(
|
||||
@JvmField val label: String,
|
||||
@JvmField val aliases: List<String> = emptyList(),
|
||||
@JvmField val enumerable: Boolean = true,
|
||||
internal val libsToInclude: List<String> = emptyList(),
|
||||
internal val assetFilesToInclude: List<String> = emptyList(),
|
||||
internal val assetDirsToExclude: List<String> = emptyList(),
|
||||
) {
|
||||
|
||||
private val BASIC = listOf(
|
||||
"libjackpal-androidterm5.so", /* Terminal Emulator. */
|
||||
"libjackpal-termexec2.so", /* Terminal Emulator. */
|
||||
)
|
||||
TERMINAL_EMULATOR(
|
||||
label = "Terminal Emulator",
|
||||
enumerable = false,
|
||||
libsToInclude = listOf(
|
||||
"libjackpal-androidterm5.so",
|
||||
"libjackpal-termexec2.so",
|
||||
),
|
||||
),
|
||||
|
||||
private val MISCELLANEOUS = emptyList<String>()
|
||||
|
||||
@JvmField
|
||||
val OPENCV = listOf(
|
||||
OPENCV(
|
||||
label = "OpenCV",
|
||||
aliases = listOf("cv"),
|
||||
libsToInclude = listOf(
|
||||
"libc++_shared.so",
|
||||
"libopencv_java4.so",
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
@JvmField
|
||||
val MLKIT_GOOGLE_OCR = listOf(
|
||||
MLKIT_OCR(
|
||||
label = "MLKit OCR",
|
||||
aliases = listOf("mlkit", "mlkitocr", "mlkit-ocr", "mlkit_ocr"),
|
||||
libsToInclude = listOf(
|
||||
"libmlkit_google_ocr_pipeline.so",
|
||||
)
|
||||
),
|
||||
assetDirsToExclude = listOf(
|
||||
"mlkit-google-ocr-models",
|
||||
),
|
||||
),
|
||||
|
||||
@JvmField
|
||||
val PADDLE_LITE = listOf(
|
||||
PADDLE_OCR(
|
||||
label = "Paddle OCR",
|
||||
aliases = listOf("paddle", "paddleocr", "paddle-ocr", "paddle_ocr"),
|
||||
libsToInclude = listOf(
|
||||
"libc++_shared.so",
|
||||
"libpaddle_light_api_shared.so",
|
||||
"libNative.so",
|
||||
)
|
||||
|
||||
val PADDLE_LITE_EXT = listOf(
|
||||
"libhiai.so",
|
||||
"libhiai_ir.so",
|
||||
"libhiai_ir_build.so",
|
||||
),
|
||||
assetDirsToExclude = listOf(
|
||||
"models",
|
||||
)
|
||||
),
|
||||
|
||||
@JvmField
|
||||
val MLKIT_BARCODE = emptyList<String>()
|
||||
|
||||
@JvmField
|
||||
val RAPID_OCR = listOf(
|
||||
RAPID_OCR(
|
||||
label = "Rapid OCR",
|
||||
aliases = listOf("rapid", "rapidocr", "rapid-ocr", "rapid_ocr"),
|
||||
libsToInclude = listOf(
|
||||
"libRapidOcr.so",
|
||||
)
|
||||
),
|
||||
assetDirsToExclude = listOf(
|
||||
"labels",
|
||||
),
|
||||
),
|
||||
|
||||
@JvmField
|
||||
val OPENCC = listOf(
|
||||
OPENCC(
|
||||
label = "OpenCC",
|
||||
aliases = listOf("cc"),
|
||||
libsToInclude = listOf(
|
||||
"libChineseConverter.so",
|
||||
)
|
||||
),
|
||||
assetDirsToExclude = listOf(
|
||||
"openccdata",
|
||||
),
|
||||
),
|
||||
|
||||
val DEFALUT_INCLUDES: List<String> = (BASIC + MISCELLANEOUS).distinct()
|
||||
PINYIN(
|
||||
label = "Pinyin",
|
||||
aliases = listOf("pin"),
|
||||
assetFilesToInclude = listOf(
|
||||
"dict-chinese-words.db.gzip",
|
||||
"dict-chinese-phrases.db.gzip",
|
||||
"dict-chinese-chars.db.gzip",
|
||||
"prob_emit.txt",
|
||||
),
|
||||
),
|
||||
|
||||
@JvmStatic
|
||||
fun ensure(name: String, libNameList: List<String>) {
|
||||
MLKIT_BARCODE(
|
||||
label = "MLKit Barcode",
|
||||
aliases = listOf("barcode", "mlkit-barcode", "mlkit_barcode"),
|
||||
assetDirsToExclude = listOf(
|
||||
"mlkit_barcode_models",
|
||||
),
|
||||
);
|
||||
|
||||
fun ensureLibFiles(moduleName: String = label) {
|
||||
if (!BuildConfig.isInrt) return
|
||||
val nativeLibraryDir = File(globalContext.applicationInfo.nativeLibraryDir)
|
||||
val primaryNativeLibraries = nativeLibraryDir.list()?.toList() ?: emptyList()
|
||||
if (!primaryNativeLibraries.containsAll(libNameList)) {
|
||||
throw Exception(globalContext.getString(R.string.error_module_does_not_work_due_to_the_lack_of_necessary_library_files, name))
|
||||
if (!primaryNativeLibraries.containsAll(libsToInclude)) {
|
||||
throw Exception(globalContext.getString(R.string.error_module_does_not_work_due_to_the_lack_of_necessary_library_files, moduleName))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
companion object {
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
object Assets {
|
||||
val defaultLibsToInclude = listOf(
|
||||
TERMINAL_EMULATOR,
|
||||
).flatMap { it.libsToInclude }
|
||||
|
||||
object File {
|
||||
|
||||
private val BASIC = listOf(
|
||||
"init.js", "roboto_medium.ttf"
|
||||
val defaultAssetFilesToInclude = listOf(
|
||||
"init.js", "roboto_medium.ttf",
|
||||
)
|
||||
|
||||
private val MISCELLANEOUS = emptyList<String>()
|
||||
|
||||
val DEFAULT_INCLUDES = (BASIC + MISCELLANEOUS).distinct()
|
||||
val defaultAssetDirsToExclude = listOf(
|
||||
"doc", "docs", "editor", "indices", "js-beautify", "sample", "stored-locales",
|
||||
) + Libs.entries.flatMap { it.assetDirsToExclude }
|
||||
|
||||
}
|
||||
|
||||
object Dir {
|
||||
|
||||
private val BASIC = listOf("doc", "docs", "editor", "indices", "js-beautify", "sample")
|
||||
|
||||
private val MISCELLANEOUS = listOf("stored-locales")
|
||||
|
||||
@JvmField
|
||||
val OPENCV = emptyList<String>()
|
||||
|
||||
@JvmField
|
||||
val MLKIT_GOOGLE_OCR = listOf("mlkit-google-ocr-models")
|
||||
|
||||
@JvmField
|
||||
val MLKIT_BARCODE = listOf("mlkit_barcode_models")
|
||||
|
||||
@JvmField
|
||||
val PADDLE_LITE = listOf("models")
|
||||
|
||||
@JvmField
|
||||
val RAPID_OCR = listOf("labels")
|
||||
|
||||
@JvmField
|
||||
val OPENCC = listOf("openccdata")
|
||||
|
||||
val DEFAULT_EXCLUDES = (BASIC + MLKIT_GOOGLE_OCR + MLKIT_BARCODE + PADDLE_LITE + RAPID_OCR + OPENCC + MISCELLANEOUS).distinct()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object Constants {
|
||||
const val OPENCV = "OpenCV"
|
||||
const val MLKIT_OCR = "MLKit OCR"
|
||||
const val PADDLE_OCR = "Paddle OCR"
|
||||
const val RAPID_OCR = "Rapid OCR"
|
||||
const val OPENCC = "OpenCC"
|
||||
const val MLKIT_BARCODE = "MLKit Barcode"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class OcrMLKit(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRun
|
||||
// ! Reserved param `options`.
|
||||
// ! zh-CN: 预留参数 `options`.
|
||||
fun recognizeTextInternal(scriptRuntime: ScriptRuntime, image: ImageWrapper, @Suppress("UNUSED_PARAMETER") options: NativeObject): List<String> {
|
||||
ApkBuilder.Libs.ensure(OcrMode.MLKIT.value, ApkBuilder.Libs.MLKIT_GOOGLE_OCR)
|
||||
ApkBuilder.Libs.MLKIT_OCR.ensureLibFiles(OcrMode.MLKIT.value)
|
||||
return scriptRuntime.ocrMLKit.recognizeText(image)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class OcrMLKit(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRun
|
||||
// ! Reserved param `options`.
|
||||
// ! zh-CN: 预留参数 `options`.
|
||||
fun detectInternal(scriptRuntime: ScriptRuntime, image: ImageWrapper, @Suppress("UNUSED_PARAMETER") options: NativeObject): List<OcrResult> {
|
||||
ApkBuilder.Libs.ensure(OcrMode.MLKIT.value, ApkBuilder.Libs.MLKIT_GOOGLE_OCR)
|
||||
ApkBuilder.Libs.MLKIT_OCR.ensureLibFiles(OcrMode.MLKIT.value)
|
||||
return scriptRuntime.ocrMLKit.detect(image)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,13 +44,13 @@ class OcrPaddle(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRu
|
||||
}
|
||||
|
||||
fun recognizeTextInternal(scriptRuntime: ScriptRuntime, image: ImageWrapper, options: NativeObject): List<String> {
|
||||
ApkBuilder.Libs.ensure(OcrMode.PADDLE.value, ApkBuilder.Libs.PADDLE_LITE)
|
||||
ApkBuilder.Libs.PADDLE_OCR.ensureLibFiles(OcrMode.PADDLE.value)
|
||||
val (cpuThreadNum, useSlim) = getOptions(options)
|
||||
return scriptRuntime.ocrPaddle.recognizeText(image, cpuThreadNum, useSlim)
|
||||
}
|
||||
|
||||
fun detectInternal(scriptRuntime: ScriptRuntime, image: ImageWrapper, options: NativeObject): List<OcrResult> {
|
||||
ApkBuilder.Libs.ensure(OcrMode.PADDLE.value, ApkBuilder.Libs.PADDLE_LITE)
|
||||
ApkBuilder.Libs.PADDLE_OCR.ensureLibFiles(OcrMode.PADDLE.value)
|
||||
val (cpuThreadNum, useSlim) = getOptions(options)
|
||||
return scriptRuntime.ocrPaddle.detect(image, cpuThreadNum, useSlim).map { result ->
|
||||
OcrResult(result.label, result.confidence, result.bounds)
|
||||
|
||||
@@ -40,7 +40,7 @@ class OcrRapid(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRun
|
||||
// ! Reserved param `options`.
|
||||
// ! zh-CN: 预留参数 `options`.
|
||||
fun recognizeTextInternal(scriptRuntime: ScriptRuntime, image: ImageWrapper, @Suppress("UNUSED_PARAMETER") options: NativeObject): List<String> {
|
||||
ApkBuilder.Libs.ensure(OcrMode.RAPID.value, ApkBuilder.Libs.RAPID_OCR)
|
||||
ApkBuilder.Libs.RAPID_OCR.ensureLibFiles(OcrMode.RAPID.value)
|
||||
return scriptRuntime.ocrRapid.recognizeText(image)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class OcrRapid(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRun
|
||||
// ! Reserved param `options`.
|
||||
// ! zh-CN: 预留参数 `options`.
|
||||
fun detectInternal(scriptRuntime: ScriptRuntime, image: ImageWrapper, @Suppress("UNUSED_PARAMETER") options: NativeObject): List<OcrResult> {
|
||||
ApkBuilder.Libs.ensure(OcrMode.RAPID.value, ApkBuilder.Libs.RAPID_OCR)
|
||||
ApkBuilder.Libs.RAPID_OCR.ensureLibFiles(OcrMode.RAPID.value)
|
||||
return scriptRuntime.ocrRapid.detect(image)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -22,7 +22,6 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.google.android.flexbox.FlexboxLayout;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
@@ -30,6 +29,7 @@ import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import org.autojs.autojs.apkbuilder.ApkBuilder;
|
||||
import org.autojs.autojs.apkbuilder.keystore.KeyStore;
|
||||
import org.autojs.autojs.core.pref.Language;
|
||||
import org.autojs.autojs.model.explorer.Explorers;
|
||||
import org.autojs.autojs.model.script.ScriptFile;
|
||||
@@ -41,10 +41,9 @@ import org.autojs.autojs.runtime.api.augment.pinyin.Pinyin;
|
||||
import org.autojs.autojs.ui.BaseActivity;
|
||||
import org.autojs.autojs.ui.common.NotAskAgainDialog;
|
||||
import org.autojs.autojs.ui.filechooser.FileChooserDialogBuilder;
|
||||
import org.autojs.autojs.apkbuilder.keystore.KeyStore;
|
||||
import org.autojs.autojs.ui.viewmodel.KeyStoreViewModel;
|
||||
import org.autojs.autojs.ui.keystore.ManageKeyStoreActivity;
|
||||
import org.autojs.autojs.ui.shortcut.AppsIconSelectActivity;
|
||||
import org.autojs.autojs.ui.viewmodel.KeyStoreViewModel;
|
||||
import org.autojs.autojs.ui.widget.RoundCheckboxWithText;
|
||||
import org.autojs.autojs.util.AndroidUtils;
|
||||
import org.autojs.autojs.util.AndroidUtils.Abi;
|
||||
@@ -65,7 +64,6 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
@@ -102,25 +100,9 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa
|
||||
put(Abi.ARMEABI, /* armeabi */ List.of("armeabi", "arme", "armv5te", "arm5te", "armv5", "v5", "arm5", "5"));
|
||||
}};
|
||||
|
||||
private static final ArrayList<String> SUPPORTED_LIBS = new ArrayList<>() {{
|
||||
add(ApkBuilder.Constants.OPENCV);
|
||||
add(ApkBuilder.Constants.MLKIT_OCR);
|
||||
add(ApkBuilder.Constants.PADDLE_OCR);
|
||||
add(ApkBuilder.Constants.RAPID_OCR);
|
||||
add(ApkBuilder.Constants.OPENCC);
|
||||
// add(ApkBuilder.Constants.PINYIN);
|
||||
add(ApkBuilder.Constants.MLKIT_BARCODE);
|
||||
}};
|
||||
private static final ArrayList<String> SUPPORTED_LIBS = new ArrayList<>();
|
||||
|
||||
private static final Map<String, List<String>> LIB_ALIASES = new HashMap<>() {{
|
||||
put(ApkBuilder.Constants.OPENCV, List.of("cv"));
|
||||
put(ApkBuilder.Constants.MLKIT_OCR, List.of("mlkit", "mlkitocr", "mlkit-ocr", "mlkit_ocr"));
|
||||
put(ApkBuilder.Constants.PADDLE_OCR, List.of("paddle", "paddleocr", "paddle-ocr", "paddle_ocr"));
|
||||
put(ApkBuilder.Constants.RAPID_OCR, List.of("rapid", "rapidocr", "rapid-ocr", "rapid_ocr"));
|
||||
put(ApkBuilder.Constants.OPENCC, List.of("cc"));
|
||||
// put(ApkBuilder.Constants.PINYIN, List.of("pin"));
|
||||
put(ApkBuilder.Constants.MLKIT_BARCODE, List.of("barcode", "mlkit-barcode", "mlkit_barcode"));
|
||||
}};
|
||||
private static final Map<String, List<String>> LIB_ALIASES = new HashMap<>();
|
||||
|
||||
private static final ArrayList<String> SIGNATURE_SCHEMES = new ArrayList<>() {{
|
||||
add("V1 + V2");
|
||||
@@ -209,6 +191,15 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa
|
||||
|
||||
private KeyStoreViewModel mKeyStoreViewModel;
|
||||
|
||||
static {
|
||||
for (ApkBuilder.Libs entry : ApkBuilder.Libs.getEntries()) {
|
||||
if (entry.enumerable) {
|
||||
SUPPORTED_LIBS.add(entry.label);
|
||||
LIB_ALIASES.put(entry.label, entry.aliases);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
||||
Reference in New Issue
Block a user