新增外置打包方式

为了彻底解决安装包体积问题,不再使用将打包模板内置到assets的方法,而是打包界面新增一个模板apk选择按钮,只要将编译好的打包模板和app一起发布就行了。另外由于时间关系,新增的资源字符串只提供了中文版,其它语言需要麻烦作者自己再处理一下
This commit is contained in:
Ai
2023-10-08 13:16:01 +08:00
committed by SuperMonster003
parent 4b64922a0b
commit 8eb29d9624
4 changed files with 54 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -61,6 +62,8 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa
private static final String LOG_TAG = "BuildActivity"; private static final String LOG_TAG = "BuildActivity";
private static final Pattern REGEX_PACKAGE_NAME = Pattern.compile("^([A-Za-z][A-Za-z\\d_]*\\.)+([A-Za-z][A-Za-z\\d_]*)$"); private static final Pattern REGEX_PACKAGE_NAME = Pattern.compile("^([A-Za-z][A-Za-z\\d_]*\\.)+([A-Za-z][A-Za-z\\d_]*)$");
EditText mSourcePath; EditText mSourcePath;
EditText mTemplatePath;
View mTemplatePathContainer;
View mSourcePathContainer; View mSourcePathContainer;
EditText mOutputPath; EditText mOutputPath;
EditText mAppName; EditText mAppName;
@@ -85,6 +88,8 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa
mSourcePath = binding.sourcePath; mSourcePath = binding.sourcePath;
mSourcePathContainer = binding.sourcePathContainer; mSourcePathContainer = binding.sourcePathContainer;
mTemplatePathContainer = binding.templatePathContainer;
mTemplatePath=binding.templatePath;
mOutputPath = binding.outputPath; mOutputPath = binding.outputPath;
mAppName = binding.appName; mAppName = binding.appName;
mPackageName = binding.packageName; mPackageName = binding.packageName;
@@ -96,6 +101,9 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa
binding.fab.setOnClickListener(v -> buildApk()); binding.fab.setOnClickListener(v -> buildApk());
binding.selectSource.setOnClickListener(v -> selectSourceFilePath()); binding.selectSource.setOnClickListener(v -> selectSourceFilePath());
binding.selectOutput.setOnClickListener(v -> selectOutputDirPath()); binding.selectOutput.setOnClickListener(v -> selectOutputDirPath());
binding.selectTemplate.setOnClickListener(
v -> selectTemplateFilePath()
);
mIcon.setOnClickListener(v -> selectIcon()); mIcon.setOnClickListener(v -> selectIcon());
setToolbarAsBack(R.string.text_build_apk); setToolbarAsBack(R.string.text_build_apk);
@@ -175,6 +183,21 @@ public class BuildActivity extends BaseActivity implements ApkBuilder.ProgressCa
super.onNewIntent(intent); super.onNewIntent(intent);
} }
void selectTemplateFilePath() {
new FileChooserDialogBuilder(this)
.title(R.string.text_template_apk_path)
.dir(Environment.getExternalStorageDirectory().getPath(), Environment.getExternalStorageDirectory().getPath())
.singleChoice(this::setTemplate)
.show();
}
private void setTemplate(File file) {
if (file.getName().toLowerCase().startsWith("inrt") && file.getName().toLowerCase().endsWith(".apk") && file.isFile()) {
mTemplatePath.setText(file.getPath());
}
}
void selectSourceFilePath() { void selectSourceFilePath() {
String initialDir = new File(mSourcePath.getText().toString()).getParent(); String initialDir = new File(mSourcePath.getText().toString()).getParent();
new FileChooserDialogBuilder(this) new FileChooserDialogBuilder(this)

View File

@@ -57,6 +57,35 @@
android:textAppearance="@style/TextAppearance.AppCompat.Body2" android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="?android:textColorSecondary" /> android:textColor="?android:textColorSecondary" />
<LinearLayout
android:id="@+id/template_path_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/text_template_apk_path">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/template_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/select_template"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/text_select"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/source_path_container" android:id="@+id/source_path_container"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -694,6 +694,7 @@
<string name="description_launcher_shortcuts">快捷方式可以在 AutoJs6 中执行特定操作, 用户可以在启动器中显示这些快捷方式, 并快速开始某些任务或启动某个活动, 如阅读 AutoJs6 应用文档, 启动 AutoJs6 设置页面等.</string> <string name="description_launcher_shortcuts">快捷方式可以在 AutoJs6 中执行特定操作, 用户可以在启动器中显示这些快捷方式, 并快速开始某些任务或启动某个活动, 如阅读 AutoJs6 应用文档, 启动 AutoJs6 设置页面等.</string>
<string name="summary_text_launcher_shortcuts">添加快捷方式到启动器</string> <string name="summary_text_launcher_shortcuts">添加快捷方式到启动器</string>
<string name="text_pin_shortcut_not_unsupported">将快捷方式固定到启动器不被支持</string> <string name="text_pin_shortcut_not_unsupported">将快捷方式固定到启动器不被支持</string>
<string name="text_template_apk_path">模板apk路径</string>
<plurals name="text_items_total_sum"> <plurals name="text_items_total_sum">
<item quantity="other">共计: %d 项</item> <item quantity="other">共计: %d 项</item>

View File

@@ -907,6 +907,7 @@
<string name="description_launcher_shortcuts">Shortcuts can perform specific actions in AutoJs6. Users can display these shortcuts in a supported launcher and quickly start some tasks or launch an activity, such as reading AutoJs6 application documentation, launching AutoJs6 settings page, and so on.</string> <string name="description_launcher_shortcuts">Shortcuts can perform specific actions in AutoJs6. Users can display these shortcuts in a supported launcher and quickly start some tasks or launch an activity, such as reading AutoJs6 application documentation, launching AutoJs6 settings page, and so on.</string>
<string name="summary_text_launcher_shortcuts">Add shortcuts to launcher</string> <string name="summary_text_launcher_shortcuts">Add shortcuts to launcher</string>
<string name="text_pin_shortcut_not_unsupported">Pinning shortcuts to launcher is not supported</string> <string name="text_pin_shortcut_not_unsupported">Pinning shortcuts to launcher is not supported</string>
<string name="text_template_apk_path">模板apk路径</string>
<plurals name="text_items_total_sum"> <plurals name="text_items_total_sum">
<item quantity="one">Total: %d item</item> <item quantity="one">Total: %d item</item>