首页 / 浏览问题 / 移动GIS / 问题详情
SuperMap iMobile示例数据运行时一直白屏且无法退出
6EXP 2023年03月15日

使用产品:imobile 11i 操作系统:win10 x64

手机Android版本:10 手机操作系统:小米10pro

按照示例写完代码后,可以成功运行,也不报错,但是app打开即闪退。

根据网上搜索来的解决方案后编写代码实现app运行弹窗选择权限后,不闪退但打开后会持续白屏且无法退出,直接将手机息屏再重新开启后自动退出。 具体代码如下

 private void requestPermissions() { //Android6.0以上设备设置动态权限
        // 检查是否拥有权限
        String[] permissions = {
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.ACCESS_WIFI_STATE,
                Manifest.permission.ACCESS_NETWORK_STATE,
                Manifest.permission.CHANGE_WIFI_STATE,
        };

        String permission = null;
        int id = 0;
        boolean isBreak = false;
        int checkCallPhonePermission = 0;
        for (int i = 0; i < permissions.length; i++) {
            permission = permissions[i];
            checkCallPhonePermission = checkSelfPermission(permission);
            if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(permissions, id);
                isBreak = true;
                break;
            }
        }
    }

许可文件和地图数据文件均按照代码中的位置放在手机中 

 String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();

        //设置许可文件路径(默认路径“/SuperMap/license/”)
        Environment.setLicensePath(rootPath + "/SuperMap/license/");

        //组件功能必须在Environment初始化之后才能调用
        Environment.initialization(this);
        setContentView(R.layout.activity_main);

        //打开工作空间
        Workspace m_workspace = new Workspace();
        WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
        info.setServer(rootPath + "/SuperMap/GeometryInfo/World.smwu");
        info.setType(WorkspaceType.SMWU);
        m_workspace.open(info);

1个回答

您好,请问那边编译器控制台或者logcat的输出结果是否有报错呢
3,690EXP 2023年03月15日

没有报错,显示运行成功

build.gradle里面 targetSdkVersion 与 compileSdkVersion注意不要超过28,还要加上ndk的配置,如:

        ndk{
//            abiFilters 'armeabi-v7a'
            abiFilters 'arm64-v8a'
        }

更改后会报错,更改代码如下

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.myapplication'
    compileSdk 28

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdk 24
        targetSdk 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ndk{
//            abiFilters 'armeabi-v7a'
        abiFilters 'arm64-v8a'
    }
    sourceSets{
        main{
            jniLibs.srcDirs=['libs']
        }
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation files('libs/com.supermap.data_v1100.jar')
    implementation files('libs/com.supermap.mapping_v1100.jar')
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

报错如下

更改了一下ndk配置代码的位置后不报错了,但targetSdk 28仍然爆红

请检查一下gradle版本,如果要用sdk28及以下版本,应该避免使用gradle6.8以上,建议设置gradle插件版本为4.1.2,gradle版本为6.7

还有关于ndk这块,abiFilters值应该与libs下面so库文件夹名称相同,即abi名称要保持一致,以上第二句评论里面使用了64位的把32位的注释了,请注意使用32位用armebai-v7a,64位用arm64-v8a

把gradle版本和插件版本降低后,尝试过多次,项目一直无法构建成功,再改回原来的版本就能构建成功,请问我应该如何降低gradle的版本,目前的报错:

build.gradle(app)

plugins {
    id 'com.android.application'
}

//android {
//    compileSdk 32
//
//    defaultConfig {
//        applicationId "com.jsdl.miscontroller"
//        minSdk 21
//        targetSdk 32
//        versionCode 1
//        versionName "1.0"
//
//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
//    }
//
//    buildTypes {
//        release {
//            minifyEnabled false
//            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
//        }
//    }
//
//    compileOptions {
//        sourceCompatibility JavaVersion.VERSION_1_8
//        targetCompatibility JavaVersion.VERSION_1_8
//    }
//}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"
    defaultConfig {
        applicationId "com.jsdl.miscontroller"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

build.gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
//plugins {
//    id 'com.android.application' version '4.1.2' apply false
//    id 'com.android.library' version '4.1.2' apply false
//}
//
//task clean(type: Delete) {
//    delete rootProject.buildDir
//}
buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
//dependencyResolutionManagement {
//    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
//    repositories {
//        google()
//        mavenCentral()
//    }
//}
rootProject.name = "My Application"
include ':app'

gradle-wrapper.properties

#Mon Apr 10 14:33:13 CST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

运行项目时的报错

安卓sdk修改为28后读取权限成功,应用得以正常运行
...