我们正在使用carto xamarin mobile sdk开发支持离线地图的应用程序。它可以正常工作,直到用户在应用程序被释放后不尝试恢复应用程序。活动创建(活动使用CARTO包管理器)崩溃,出现异常:

Carto.PackageManager.CartoPackageManager.CartoPackageManager(string source, string dataFolder)<01980a2dae7148abb92e6b982667f448>:0
App.Droid.OfflineMaps.AndroidMapPackageManager.AndroidMapPackageManager()<76ae23b9271c407d865ebb6162639870>:0
App.Droid.Plugins.MapDownloader.Plugin.<>c.<Load>b__0_0()<76ae23b9271c407d865ebb6162639870>:0
MvvmCross.Platform.IoC.MvxSimpleIoCContainer.<>c__DisplayClass33_0<TInterface>.<RegisterSingleton>b__0()<4ddde23419c5494288c799fcdbb0f189>:0
MvvmCross.Platform.IoC.MvxSimpleIoCContainer.ConstructingSingletonResolver.Resolve()<4ddde23419c5494288c799fcdbb0f189>:0
MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve(Type type, MvxSimpleIoCContainer.IResolver resolver, ref object resolved
App.Core.ViewModels.Blocks.Maps.Offline.MapDownloaderOwnerViewModel.EnableMapDownloader(City city)<d6cca792b401420d922bc024

Here on line 105 you can see where exception is originally thrown.
在常规的输入页面中,它工作得很好。
packagemanager请求通过以下方式在页面视图模型的ctor中发生:
 Mvx.Resolve<MapDownloadsManager>(); // It receivs as injection platform-dependent packageManager

似乎问题出在数据库路径上。
我们正在生成文件夹名称,然后按以下方式传递给CartoPackageManager构造函数:
 private static string CreateFolder(string folderPath)
        {

        var folder = GetDocumentDirectory(folderPath);

        if (!Directory.Exists(folder))
        {
            Directory.CreateDirectory(folder);
        }

        return folder;
    }

    private static string GetDocumentDirectory(string withFolder = null)
    {
        var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

        return withFolder == null ? documents : Path.Combine(documents, withFolder + "/");
    }

你知道问题的根源在哪里吗?
附:Carto SDKv4.0.2,MVVMCross4.4.0,很遗憾现在不能更新到新版本。
经过一些研究,我发现任务队列已重置,现在假设应用程序在源代码中实际崩溃:
 std::string taskDbFileName = "tasks_v1.sqlite";
        try {
            _taskQueue = std::make_shared<PersistentTaskQueue>(createLocalFilePath(taskDbFileName));
        }
        catch (const std::exception& ex) {
            //This looks like: Error while constructing PackageManager: Package encryption keys do not match, trying to remove
            Log::Errorf("PackageManager: Error while constructing PackageManager::PersistentTaskQueue: %s, trying to remove...", ex.what());
            _taskQueue.reset();
            utf8_filesystem::unlink(taskDbFileName.c_str());
            try {
                _taskQueue = std::make_shared<PersistentTaskQueue>(createLocalFilePath(taskDbFileName));
            }
            catch (const std::exception& ex) {
                **throw FileException("Failed to create/open package manager task queue database", taskDbFileName); //App gets here.**
            }
        }

包管理器的初始化:
 public class AndroidMapPackageManager : PackageManagerListener, IPackageManger
    {
        private readonly CartoPackageManager _packageManager;

        public AndroidMapPackageManager()
        {
            var folder = CreateFolder(OfflineMapStrings.MapsFolderName); // /data/user/0/com.app.cityguide/files/mapmap2/

 _packageManager =
                    new CartoPackageManager(OfflineMapsStrings.PackageManagerSource, folder)
                    {
                        PackageManagerListener = this
                    };
       }
}

我是在构造函数在其他类订阅侦听器事件之后才启动它的。坦白地说,我从来没有停止过。我需要吗?
与填充物的导电率是100%。我使用的调试模式没有后台允许,现在我尝试内存填充和结果是一样的。
许可证问题:
05-25 12:41:41.091 26101 26101 E carto-mobile-sdk: CartoPackageManager: RegisterLicense not called, using random key for package encryption!
05-25 12:41:41.094 26101 26101 E carto-mobile-sdk: PackageManager: Error while constructing PackageManager: Package encryption keys do not match, trying to remove

最佳答案

问题是我正在splashActivity中注册许可证密钥。但是,在恢复splash活动之后并没有显示,而且,很明显,没有执行许可证密钥的注册。我已经将它移到自定义应用程序类,它成功了:

public class CustomApplication : Application
{
        public override void OnCreate()
        {
            base.OnCreate();
            MapView.RegisterLicense(CartoApiKey, this);
        }
}

10-07 21:24