注册时间
最后登录
新帖
发布在 bug、问题、建议 阅读更多

我的项目在 autox.js 中运行是正常的,也不会报错,功能也正常,但是我将项目打包成应用后
运行会报错

报错日志:
12:49:55.159/E: Thread[main (Spawn-2),5]: no bridges set

java.lang.IllegalStateException: no bridges set
at com.stardust.autojs.runtime.ScriptBridges.checkBridges(ScriptBridges.java:40)
at com.stardust.autojs.runtime.ScriptBridges.toString(ScriptBridges.java:50)
at com.stardust.autojs.engine.RhinoJavaScriptEngine$WrapFactory.wrap(RhinoJavaScriptEngine.kt:156)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:227)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1879)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1061)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:90)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:380)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3869)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:88)
at org.mozilla.javascript.InterfaceAdapter.invokeImpl(InterfaceAdapter.java:171)
at org.mozilla.javascript.VMBridge_custom$InterfaceAdapterWrapper.invokeImpl(VMBridge_custom.java:149)
at org.mozilla.javascript.VMBridge_custom$InterfaceAdapterWrapper.lambda$invoke$0$org-mozilla-javascript-VMBridge_custom$InterfaceAdapterWrapper(VMBridge_custom.java:131)
at org.mozilla.javascript.VMBridge_custom$InterfaceAdapterWrapper$$ExternalSyntheticLambda0.run(Unknown Source:13)
at org.mozilla.javascript.VMBridge_custom$InterfaceAdapterWrapper.call(VMBridge_custom.java:140)
at org.mozilla.javascript.VMBridge_custom$InterfaceAdapterWrapper.invoke(VMBridge_custom.java:132)
at org.mozilla.javascript.VMBridge_custom.lambda$newInterfaceProxy$0$org-mozilla-javascript-VMBridge_custom(VMBridge_custom.java:65)
at org.mozilla.javascript.VMBridge_custom$$ExternalSyntheticLambda0.invoke(Unknown Source:15)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy6.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:233)
at com.stardust.autojs.core.looper.TimerThread.run(TimerThread.java:46)

相关部分代码:

主程序:(main.js)

/////////////////////////////////
//导入功能//////////////////////
////////////////////////////////
ui.list.on("item_bind", function(itemView, itemHolder) {
    itemView.Import_file.on("click", function() {
        let item = itemHolder.item;
toast("正在加载  正在备份...")

       
        //  toast(item.filename)
        //备份
        $files.create("/storage/emulated/0/huangyx.MC存档/备份/");
        //目录路径
        var dir = ("/storage/emulated/0/Android/data/" + gamename + "/files/minecraftWorlds/" + item.filename + "/");
        //文件路径
        var filePath = ("/storage/emulated/0/huangyx.MC存档/备份/ " + item.filename + ".zip");
        // 压缩文件
        $files.remove(filePath);
        $zip.zipDir(dir, filePath);
//        sleep(3000)
        engines.execScriptFile("file_preview.js")
        storage.put("file_preview", "false");

        threads.start(function() {
            for (;;) {
                file_preview = (storage.get("file_preview"))
                sleep(100)
                if (file_preview == "true") {
                    log("返回文件: " + storage.get("file"))
                    break

                }
            }
            files.removeDir("/storage/emulated/0/huangyx.MC存档/缓存/")
            files.ensureDir("/storage/emulated/0/huangyx.MC存档/缓存/")
            $zip.unzip((storage.get("file")), ("/storage/emulated/0/huangyx.MC存档/缓存/"));
            
            $zip.unzip((storage.get("file")), ("/storage/emulated/0/Android/data/" + gamename + "/files/minecraftWorlds/"));
           
            filename=files.listDir("/storage/emulated/0/huangyx.MC存档/缓存/")
            console.warn(filename[0])
            log(files.getNameWithoutExtension(storage.get("file")))
         
            files.removeDir(dir)
            files.rename(("/storage/emulated/0/Android/data/" + gamename + "/files/minecraftWorlds/" + filename[0]), (item.filename))
            
            storage.put("gamename", ui.content.text());
    storage.put("open", "true")
    engines.execScriptFile("begin.js") //重启 相当于engines.execScriptFile("main.js")
    exit()
            
            
            
        })
    })
})

文件选择,子程序(file_preview.js)

"ui";
var storage = storages.create("huangyx:MC存档")
ui.layout(
    <vertical>
    <frame>
        <vertical>
            <ScrollView>
                <vertical>
                    <list id="list" margin="0 20">
                        <vertical>
                            <card w="300" h="40" margin="10 5" cardCornerRadius="2dp"
                            cardElevation="1dp" gravity="center_vertical">
                            <text text="{{filename}}" textColor="#000000" textSize="18sp" padding="18 5"/>
                            <horizontal gravity="right" h="auto">
                            <button id="Export_file" text="选择"w="70" h="40"/>
                            </horizontal>
                            <View id="view_list" bg="#2196f3" h="*" w="10"/>
                        </card>
                    </vertical>
                </list>
                
                
                
                <card margin="20 0" padding="16" w="auto" h="auto" radius="20dp" scaleType="fitXY">
                    <vertical bg="#ffd2ef"/>
                    <img src="https://i0.hdslb.com/bfs/album/699aa8fe5efc28d55095262dd74dcf0f229e4990.jpg" w="30" h="30" radius="10dp" scaleType="fitXY" margin="15 16"/>
                    <text id="author" text="by:huangyx" textColor="black" textSize="13sp" margin="50 18"/>
                </card>
                <vertical>
                    <text id="remind" text="////根目录下的压缩包文件//// (/storage/emulated/0/*.zip)" textColor="#999999" textSize="14sp" padding="18 5"/>
                </vertical>
            </vertical>
        </ScrollView>
        
    </vertical>
    </frame>
    </vertical>
)

//读取文件/////////////////
dt = files.listDir("/storage/emulated/0")
dtcs = -1
archive1 = ""
for (i = 0; i < 114514;) {
    dtcs = dtcs + 1
    archive = dt[dtcs]
 //   log(archive)
 //   log(files.getExtension(archive))
    if (archive == undefined) {
        break
    }

    if (files.getExtension(archive) == "zip") {
        archive1 = ("" + archive1 + '{"filename":"' + archive + '"},')
    }
    // log(archive1)

}
var data = ("[" + archive1 + "]")
//log(data)
var str = JSON.parse(data)
console.log(typeof str);
items = (str)
//log(items)
ui.list.setDataSource(items)
////////////
ui.remind.setText("////根目录下的压缩包文件////\n//// (/storage/emulated/0/*.zip)\n此操作会覆盖存档,之前的内容会消失,如果取消操作请返回\n压缩包格式: 文件.zip/文件夹/存档内容")

ui.list.on("item_bind", function(itemView, itemHolder) {
    itemView.Export_file.on("click", function() {
        let item = itemHolder.item;
        files.removeDir("/storage/emulated/0/huangyx.MC存档/" + item.filename+"/")
        storage.put("file","/storage/emulated/0/" + item.filename)
        
   //     files.copy("/storage/emulated/0/huangyx.MC存档/" + files.getNameWithoutExtension(item.filename)+"", "/storage/emulated/0/huangyx.MC存档/测试文件夹/")
        storage.put("file_preview", "true")
        exit()
    });
})