gpt4 book ai didi

java - 从大型数据库中读取

转载 作者:行者123 更新时间:2023-12-02 11:44:13 25 4
gpt4 key购买 nike

我正在编写一个应用程序,需要加载和读取数据库。该数据库大约 900MB。当我将其复制到我的应用程序目录中的 \assets\databases 时,android studio 上会弹出 java 堆空间错误。我使用 org.gradle.jvmargs=-Xmx4608m 增加了堆空间。我还尝试了在网上找到的其他解决方案,但我的问题仍然存在。我还知道 apk 文件的大小是有限制的。这可能会导致 java 堆空间错误,因为我的数据库太大,无法作为 apk 的一部分加载。

有什么替代方案吗?如何从 Android 应用程序读取数据库,而无需将数据库物理保存在 .apk 文件中。

这是构建错误的堆栈跟踪

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageDebug'.
> Java heap space

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:packageDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.tooling.BuildException: Java heap space
at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$10(OutputScope.java:241)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:236)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:197)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:181)
at com.android.build.gradle.tasks.PackageAndroidArtifact.doFullTaskAction(PackageAndroidArtifact.java:471)
at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:109)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
... 27 more
Caused by: java.lang.OutOfMemoryError: Java heap space
at com.google.common.io.ByteStreams.toByteArray(ByteStreams.java:165)
at com.android.apkzlib.zip.StoredEntry.read(StoredEntry.java:346)
at com.android.apkzlib.sign.SigningExtension.onZipEntryOutput(SigningExtension.java:256)
at com.android.apkzlib.sign.SigningExtension.access$400(SigningExtension.java:55)
at com.android.apkzlib.sign.SigningExtension$1.lambda$added$0(SigningExtension.java:164)
at com.android.apkzlib.sign.SigningExtension$1$$Lambda$378/1751952517.run(Unknown Source)
at com.android.apkzlib.zip.ZFile.notify(ZFile.java:2099)
at com.android.apkzlib.zip.ZFile.addToEntries(ZFile.java:1746)
at com.android.apkzlib.zip.ZFile.processAllReadyEntries(ZFile.java:1687)
at com.android.apkzlib.zip.ZFile.processAllReadyEntriesWithWait(ZFile.java:1708)
at com.android.apkzlib.zip.ZFile.hasPendingChangesWithWait(ZFile.java:2517)
at com.android.apkzlib.zfile.ApkZFileCreator.hasPendingChangesWithWait(ApkZFileCreator.java:180)
at com.android.builder.internal.packaging.IncrementalPackager.hasPendingChangesWithWait(IncrementalPackager.java:319)
at com.android.build.gradle.tasks.PackageAndroidArtifact.doTask(PackageAndroidArtifact.java:694)
at com.android.build.gradle.tasks.PackageAndroidArtifact.splitFullAction(PackageAndroidArtifact.java:522)
at com.android.build.gradle.tasks.PackageAndroidArtifact$$Lambda$327/1788085017.processSplit(Unknown Source)
at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$6(OutputScope.java:186)
at com.android.build.gradle.internal.scope.OutputScope$$Lambda$328/436614112.processSplit(Unknown Source)
at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$7(OutputScope.java:203)
at com.android.build.gradle.internal.scope.OutputScope$$Lambda$329/792075765.processSplit(Unknown Source)
at com.android.build.gradle.internal.scope.OutputScope.lambda$null$8(OutputScope.java:225)
at com.android.build.gradle.internal.scope.OutputScope$$Lambda$331/1881111235.call(Unknown Source)
at com.android.ide.common.internal.WaitableExecutor.waitForAllTasks(WaitableExecutor.java:215)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:235)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:197)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(Output Scope.java:181)


* Get more help at https://help.gradle.org

BUILD FAILED in 3m 24s

最佳答案

使用rest api?说实话,每台设备上都有如此大的数据库的情况确实很少见,想象一下您想要更新应用程序 - 用户每次都应该重新下载整个应用程序。

如果您需要在设备上拥有那么大的数据库,您应该拥有可以在应用程序启动时下载和执行的 SQL 脚本。这样就可以解决更新问题了。但无论如何你都应该有一些网络服务。

关于java - 从大型数据库中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48321561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com