【问题标题】:"OutOfMemoryError: unable to create new native thread" after adding Google Play Services添加 Google Play 服务后出现“OutOfMemoryError:无法创建新的本机线程”
【发布时间】:2016-09-24 13:28:28
【问题描述】:

我正在尝试实施广告网络的 SDK,它需要我添加 Google Play 服务。

现在,当我将 compile 'com.google.android.gms:play-services:9.6.0' 添加到我的 gradle 文件时,我收到一个错误(见底部)。这可能是由于已经安装了一些其他库,但我不知道如何修复这些文件。

项目等级:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

模块分级:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.google.android.gms:play-services-appindexing:9.6.1'
    compile 'com.google.android.gms:play-services:9.6.0' // The new line
}
apply plugin: 'com.google.gms.google-services'

错误:

错误:任务“:appName:mergeDebugResources”执行失败。 java.lang.OutOfMemoryError: 无法创建新的本地线程

如前所述:没有新行,它运行完美。

【问题讨论】:

  • 问题似乎出在您的开发机器上,因为您甚至无法编译。你看到mastertheboss.com/jboss-server/jboss-monitoring/… 来帮助诊断问题了吗?
  • 基于此thread,每当 JVM 向操作系统请求新线程时,都会导致您的错误 java.lang.OutOfMemoryError: unable to create new native thread。每当底层操作系统无法分配新的本机线程时,就会抛出这个OutOfMemoryError。只需检查上面的链接即可了解此问题的可能原因和解决方案。欲了解更多信息,请查看相关SO question

标签: android google-play-services


【解决方案1】:

因为您添加了“com.google.android.gms:play-services-appindexing:9.6.1” 然后添加 compile 'com.google.android.gms:play-services:9.6.0'

如果你不需要所有的播放服务,只需添加你需要的,因为这会产生一个大的 apk 文件,有时会产生 OutOfMemoryError

如果您想通过将此行添加到项目的“gradle-properties”来更改 JVM(Heapsize)的配置:

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

【讨论】:

  • 注释 appindexing 行并将另一行添加到 cradle-properties 都不会改变任何内容。
  • 尝试使用对我有用的 'play-services:9:0:2'
猜你喜欢
  • 1970-01-01
  • 2015-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多