20260315_193958_991
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sun Mar 15 05:42:10 GMT 2026
|
||||
#Sun Mar 15 11:38:00 GMT 2026
|
||||
stageCount=26
|
||||
libraryProject=
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.25
|
||||
buildCount=8
|
||||
buildCount=10
|
||||
baseBetaVersion=15.11.26
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.winboll.models.NfcTermuxCmd;
|
||||
@@ -12,6 +13,7 @@ import com.google.gson.Gson;
|
||||
public class NfcTermuxBridgeActivity extends Activity {
|
||||
|
||||
private static final String TAG = "NfcTermuxBridge";
|
||||
private static final String ACTION_BUILD_VIEW = NfcTermuxBridgeActivity.class.getName() + ".ACTION_BUILD_VIEW";
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
@Override
|
||||
@@ -23,7 +25,11 @@ public class NfcTermuxBridgeActivity extends Activity {
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
handleNfcIntent(intent);
|
||||
if (intent.getAction().equals(ACTION_BUILD_VIEW)) {
|
||||
onOpenTermuxProjectBuildView(intent);
|
||||
} else {
|
||||
handleNfcIntent(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,6 +88,96 @@ public class NfcTermuxBridgeActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试执行Gradle命令(实时输出版,唤起Termux窗口)
|
||||
*/
|
||||
public void onOpenTermuxProjectBuildView(Intent intent) {
|
||||
try {
|
||||
String json = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
|
||||
// 1. 发布版逻辑:正常接收 NFC 传入的 JSON
|
||||
if (json == null || json.isEmpty()) {
|
||||
LogUtils.e(TAG, "NFC 指令为空");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
LogUtils.d(TAG, "接收 JSON:" + json);
|
||||
|
||||
// 2. 解析指令
|
||||
NfcTermuxCmd cmd = GSON.fromJson(json, NfcTermuxCmd.class);
|
||||
if (cmd.script == null || cmd.script.isEmpty()) {
|
||||
LogUtils.e(TAG, "script 不能为空");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 拼接脚本路径
|
||||
// String scriptPath = "/data/data/com.termux/files/home/TermuxWorkSpaces/BashShells/AutoNFC/" + cmd.script;
|
||||
//
|
||||
// // 4. 执行 Termux 命令
|
||||
// boolean success = TermuxCommandExecutor.executeCommand(
|
||||
// this,
|
||||
// scriptPath,
|
||||
// cmd.args,
|
||||
// cmd.workDir,
|
||||
// cmd.background,
|
||||
// cmd.resultDir
|
||||
// );
|
||||
|
||||
// LogUtils.d(TAG, "onTestTermuxCMD() 按钮点击,执行Gradle命令(实时输出)");
|
||||
// //tvMessage.append("\n【测试:执行Gradle命令(实时输出)】\n");
|
||||
//
|
||||
// // 1. 校验Termux是否安装
|
||||
// if (!TermuxCommandExecutor.isTermuxInstalled(this)) {
|
||||
// LogUtils.e(TAG, "onTestTermuxCMD() 错误:未安装Termux应用");
|
||||
// //tvMessage.append("错误:未安装Termux应用(包名:com.termux)\n");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 2. 定义核心路径(确保路径与Termux中一致)
|
||||
// String gradleFullPath = "/data/data/com.termux/files/home/gradle/gradle-7.5.1/bin/gradle";
|
||||
// String projectPath = TERMUX_HOME_PATH + "/"; // 项目目录
|
||||
//
|
||||
// 3. 构造命令(核心:用stdbuf禁用缓冲,实现实时输出)
|
||||
String targetCmd = "";
|
||||
// 步骤1:进入项目目录(不存在则创建)
|
||||
targetCmd += "cd " + cmd.workDir + " && ";
|
||||
// 步骤2:加载环境变量
|
||||
targetCmd += "source ~/.bashrc && ";
|
||||
// 步骤3:显式配置PATH
|
||||
//targetCmd += "export PATH=/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/home/gradle/gradle-7.5.1/bin:$PATH && ";
|
||||
// 步骤4:用stdbuf禁用stdout/stderr缓冲(关键!),执行Gradle命令
|
||||
// -o0:stdout无缓冲;-e0:stderr无缓冲;-i0:stdin无缓冲
|
||||
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " task --all | grep assemble && ";
|
||||
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " -Pandroid.aapt2FromMavenOverride=/data/data/com.termux/files/home/android-sdk/build-tools/34.0.4/aapt2 assembleBetaDebug && ";
|
||||
targetCmd += "stdbuf -o0 -e0 -i0 bash && ";
|
||||
// 步骤5:执行成功提示
|
||||
targetCmd += "echo '\n✅ 命令执行完成!' && echo '\n📌 项目名称:" + cmd.args + "' && read -p '按回车键关闭终端...'";
|
||||
|
||||
|
||||
// 4. 执行命令(终端会话模式,唤起Termux窗口)
|
||||
boolean cmdSuccess = TermuxCommandExecutor.executeTerminalCommand(this, targetCmd);
|
||||
|
||||
// 5. 结果反馈
|
||||
if (cmdSuccess) {
|
||||
Toast.makeText(this, "指令已发送:" + cmd.script + " " + cmd.args, Toast.LENGTH_SHORT).show();
|
||||
LogUtils.i(TAG, "执行成功:" + cmd.script + " " + cmd.args);
|
||||
} else {
|
||||
Toast.makeText(this, "指令发送失败", Toast.LENGTH_SHORT).show();
|
||||
LogUtils.e(TAG, "执行失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "处理异常:" + e.getMessage(), e);
|
||||
Toast.makeText(this, "解析失败", Toast.LENGTH_SHORT).show();
|
||||
} finally {
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
// 公共静态测试函数:外部可直接调用注入测试 JSON
|
||||
// ===========================================================
|
||||
@@ -100,5 +196,27 @@ public class NfcTermuxBridgeActivity extends Activity {
|
||||
LogUtils.e(TAG, "测试指令注入失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================
|
||||
// 公共静态测试函数:外部可直接调用注入测试 JSON
|
||||
// ===========================================================
|
||||
public static void testViewCommand(Context context) {
|
||||
try {
|
||||
// 测试用指令
|
||||
String testJson = "{\"script\":\"BuildWinBoLLProjectView.sh\",\"args\":[\"DebugTemp\"],\"workDir\":null,\"background\":true,\"resultDir\":null}";
|
||||
|
||||
Intent testIntent = new Intent(context, NfcTermuxBridgeActivity.class);
|
||||
testIntent.setAction(ACTION_BUILD_VIEW);
|
||||
testIntent.putExtra(Intent.EXTRA_TEXT, testJson);
|
||||
|
||||
// 模拟跳转至自身 Activity
|
||||
context.startActivity(testIntent);
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "测试指令注入失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -218,9 +218,14 @@ public class TermuxEnvTestActivity extends BaseWinBoLLActivity {
|
||||
}
|
||||
|
||||
public void onTestWinBoLLProjectBuild(View view) {
|
||||
ToastUtils.show("onOpenTermuxBash");
|
||||
ToastUtils.show("onTestWinBoLLProjectBuild");
|
||||
NfcTermuxBridgeActivity.testCommand(this);
|
||||
}
|
||||
|
||||
public void onTestWinBoLLProjectBuildView(View view) {
|
||||
ToastUtils.show("onTestWinBoLLProjectBuildView");
|
||||
NfcTermuxBridgeActivity.testViewCommand(this);
|
||||
}
|
||||
|
||||
public void onOpenTermuxBash(View view) {
|
||||
LogUtils.d(TAG, "onTestTermuxCMD() 按钮点击,执行Gradle命令(实时输出)");
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right">
|
||||
|
||||
|
||||
<Button
|
||||
android:textAllCaps="false"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -37,7 +37,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Test Termux Env"
|
||||
android:onClick="onTestTermuxEnv"/>
|
||||
|
||||
|
||||
<Button
|
||||
android:textAllCaps="false"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -45,6 +45,13 @@
|
||||
android:text="Test WinBoLL Project Build"
|
||||
android:onClick="onTestWinBoLLProjectBuild"/>
|
||||
|
||||
<Button
|
||||
android:textAllCaps="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Test WinBoLL Project Build View"
|
||||
android:onClick="onTestWinBoLLProjectBuildView"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ScrollView
|
||||
|
||||
Reference in New Issue
Block a user