我们正在使用 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
在常规输入页面中它工作正常。PackageManager 请求通过以下方式在页面 ViewModel 的 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 + "/");
}
你有什么想法可能是问题的根源吗?
PS:Carto SDK v 4.0.2,MvvmCross 4.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
};
}
}
我在其他类订阅监听器事件后构造函数工作后启动它。而且,坦率地说,我从不停止它。我需要吗?
使用 FIllRam 的再现性为 100%。我使用了不允许背景的调试模式,现在我尝试了 Ram Filler,结果是一样的。
许可证问题:
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