为什么 Carto Package Manager 在恢复后无法连接到它的数据库?
Why does Carto Package Manager can't connect to it's database after resuming?
我们正在使用 Carto Xamarin Mobile SDK 开发支持离线地图的应用程序。它工作正常,直到用户在处理后不尝试恢复应用程序。 Activity 创建(activity 使用 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 请求通过以下方式在页面 ViewModel 的构造函数中发生:
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 + "/");
}
您知道问题的根源在哪里吗?
P.S.: 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
};
}
}
我在其他 class 订阅侦听器事件后构造函数工作后立即启动它。而且,坦率地说,我从不阻止它。我需要它吗?
具有 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
问题是我在 SplashActivity 中注册了许可证密钥。但是,在恢复启动后 activity 没有显示,显然,没有执行许可证密钥的注册。我已将其移至自定义应用程序 class 并且有效:
public class CustomApplication : Application
{
public override void OnCreate()
{
base.OnCreate();
MapView.RegisterLicense(CartoApiKey, this);
}
}
我们正在使用 Carto Xamarin Mobile SDK 开发支持离线地图的应用程序。它工作正常,直到用户在处理后不尝试恢复应用程序。 Activity 创建(activity 使用 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 请求通过以下方式在页面 ViewModel 的构造函数中发生:
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 + "/");
}
您知道问题的根源在哪里吗?
P.S.: 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
};
}
}
我在其他 class 订阅侦听器事件后构造函数工作后立即启动它。而且,坦率地说,我从不阻止它。我需要它吗?
具有 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
问题是我在 SplashActivity 中注册了许可证密钥。但是,在恢复启动后 activity 没有显示,显然,没有执行许可证密钥的注册。我已将其移至自定义应用程序 class 并且有效:
public class CustomApplication : Application
{
public override void OnCreate()
{
base.OnCreate();
MapView.RegisterLicense(CartoApiKey, this);
}
}