首页 / 浏览问题 / 移动GIS / 问题详情
移动端workspace打开smwu文件失败
4EXP 2025年04月22日

sdk环境为 11i,jar包版本为v1111

在项目中刚开始创建时是没有问题的,但多次退出打开后,会出现

Workspace打不开smwu文件
WorkspaceConnectionInfo _wkInfo = m_workspace.getConnectionInfo();
//设置服务地址
_wkInfo.setServer(SuperMapConfig.DEFAULT_DATA_PATH + m_prjId + "/" + m_prjId + ".smwu");
//工作空间名字
_wkInfo.setName(m_prjId);
//工作空间类型
_wkInfo.setType(WorkspaceType.SMWU);
if (!m_workspace.open(_wkInfo)) {
    message.what = 3;
    message.obj = "line#446工作空间打开失败";
    m_handler.sendMessage(message);
    return;
}

现在特别容易出现这种问题的手机为HUAWEI Pura 70 pro+ ,Harmonyos 版本:4.2.0 在小米手机也类似出现这种问题但不多,这是操作的问题还是框架的问题,因为在退出当前工作路径时框架释放资源过程比较慢。

1个回答

看代码片段逻辑没有问题,提到多次打开才会出现的问题,怀疑上上下文多次交互的逻辑问题,有几点需要确认排查下:

1、workspace对象不支持同时打开多个smwu文件,每次退出是否有关闭smwu文件的打开,关闭后再打开smwu文件。每次操作结果日志记录下。看逻辑是否正确。

2、如果smwu打开结果是失败,看看sdk层面日志是否有报错,需要确保smwu文件路径正确、类型正确、工作空间名称是唯一不重复的。
1,615EXP 2025年04月22日

首先,谢谢你的答复

打开smwu文件失败并不是经常出现的,出现问题时因不是第一现场很难查看报错日记,唯一知道是smwu文件可能是已经损坏了,在workspace上打不开或者说workspace.open(prjectPath)为false。(在SuperMap iDesktopX 11i是可以打开获取数据的)
在我使用workspace.open打开“损坏的smwu”时是没有报错信息的,只是返回false。

下面是代码和输出信息。

代码:(s2025-04-11-2.smwu为损坏文件,2025-04-08-sadaw.smwu是正常工作空间加载的,他是可以被workspace加载)

//        String filePath=Constant.SDCARD+"/Download/smwuTest/0408/2025-04-08-sadaw.smwu";
        String filePath=Constant.SDCARD+"/Download/smwuTest/0411/s2025-04-11-2.smwu";
        boolean isExist=new File(filePath).exists();
        if (!isExist){
            Log.e(TAG,"加载"+filePath+"文件失败");
            finish();
            return;
        }
        mapView=findViewById(R.id.mapview);
        findViewById(R.id.refreshBtn).setOnClickListener(this);
        findViewById(R.id.test).setOnClickListener(this);
        line=findViewById(R.id.line);
        sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
        zoomControls=findViewById(R.id.zoom);
        workspace=new Workspace();
        workspace.setCaption(NAME);
        workspace.setDescription(NAME);

        WorkspaceConnectionInfo info=workspace.getConnectionInfo();
        info.setServer(filePath);
        info.setType(WorkspaceType.SMWU);
        info.setName(NAME);


        boolean state = workspace.open(info);
        mapControl=mapView.getMapControl();
        map=mapControl.getMap();
        map.setWorkspace(workspace);
        Maps maps=workspace.getMaps();
        if (maps.getCount()<=0){
            Log.e(TAG,"图层缺失");
            finish();
            return;
        }
        try {
            map.open(maps.get(0));
        }catch (Exception e){
            finish();
        }

Logcat打开s2025-04-11-2.smwu的输出信息

2025-04-22 16:42:56.943 17704-17704 ziparchive              com.tianchi.test0414suwu             E  Zip: lseek on fd -2 failed: Bad file descriptor
2025-04-22 16:42:56.945 17704-17704 hi.test0414suwu         com.tianchi.test0414suwu             I  type=1400 audit(0.0:160987): avc: denied { open } for path="/system/etc/mumu-configs/currentApp" dev="sdc3" ino=5112230 scontext=u:r:untrusted_app:s0:c179,c256,c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1 app=com.tianchi.test0414suwu
2025-04-22 16:42:57.475 17704-17704 Thread-1                com.tianchi.test0414suwu             I  type=1400 audit(0.0:160988): avc: denied { connectto } for path="/dev/socket/dnsproxyd" scontext=u:r:untrusted_app:s0:c179,c256,c512,c768 tcontext=u:r:init:s0 tclass=unix_stream_socket permissive=1 app=com.tianchi.test0414suwu
2025-04-22 16:42:57.589 17704-17704 MainActivity            com.tianchi.test0414suwu             D  license is valid
2025-04-22 16:42:57.681 17704-17704 MainActivity            com.tianchi.test0414suwu             E  图层缺失
2025-04-22 16:42:57.687 17704-17704 Choreographer           com.tianchi.test0414suwu             I  Skipped 44 frames!  The application may be doing too much work on its main thread.
2025-04-22 16:42:57.719 17704-17781 Supermap                com.tianchi.test0414suwu             I  true
2025-04-22 16:42:57.828 17704-17785 Supermap                com.tianchi.test0414suwu             I  true
2025-04-22 16:42:57.979 17704-17788 Supermap                com.tianchi.test0414suwu             I  true
2025-04-22 16:42:59.674 17704-17704 Choreographer           com.tianchi.test0414suwu             I  Skipped 114 frames!  The application may be doing too much work on its main thread.

还有就是“下文多次交互”具体的操作是什么呢。
“ Zip: lseek on fd -2 failed: Bad file descriptor”提示是指有个zip文件解压失败?

日志信息看,没有与imobile for android组件接口的报错提示。

从代码里看 isExist、state 的值都为true吗?如果为false,对应的smwu文件第二次是否能打开?

下文多次交互”是指是否在多处调用 workspace.open打开同一个smwu文件。程序关闭或切换smwu文件时,需要调用workspace.close接口将当前工作空间关闭。
你好,

在打开正常的smwu文件(2025-04-08-sadaw.smwu),也会出现Zip: lseek on fd -2 failed: Bad file descriptor这个,确定是workspace能打开的,isExist=true,state=true

在打开损坏的smwu文件(s2025-04-11-2.smwu),workspaced打不开,isExist=true,state=false

在项目工作空间推出去时的代码设置:

@Override
protected void onDestroy() {
    super.onDestroy();
    try {
        if (m_map != null) {
            m_map.save();
        }
        if (m_workspace != null) {
            m_workspace.save();
        }
        LogUtills.i(TAG, "onDestroy = save()");

    } catch (Exception e) {
        LogUtills.i(TAG, "onDestroy" + e.getMessage());
    } finally {
        if (m_map != null) {
            m_map.close();
            m_map = null;
            m_mapControl.dispose();
        }
        if (m_workspace != null) {
            m_workspace.close();
            m_workspace.dispose();
            m_workspace = null;
        }
        EventBus.getDefault().unregister(this);
    }
    LogUtills.i(TAG, "onDestroy()" + this.toString());
}
在MapActivity退出时执行onDestroy()中执行资源释放,在资源释放过程中是否会有耗时?,如在MapActivity执行onDestroy()退出后,用户马上打开新MapActivity相同工作空间这会不会产生smwu文件损坏从而导致打不开?

还有就是在公司项目中smwu文件打开是在线程池中进行操作的,假如用户在打开smwu文件的过程中Activity马上退出,线程还在执行,但Activity onDestroy()已经被执行了,可能会存在supermap资源没有被释放再次打开,也会出现smwu文件损坏从而导致打不开?

下面是公司项目打开smwu的代码,会有点乱(毕竟是有几代主人)

...