【发布时间】:2016-09-22 15:44:56
【问题描述】:
在我的项目中包含播放服务和 firebase 库后,目前正在开发我的 android 应用程序,但出现此错误并且无法运行我的代码
:app:prePackageMarkerForDebug :app:transformClassesWithDexForDebug 要在进程中运行 dex,Gradle 守护进程需要更大的堆。 它目前大约有 910 MB。 要加快构建速度,请将 Gradle 守护程序的最大堆大小增加到 2048 MB 以上。 为此,请在项目 gradle.properties 中设置 org.gradle.jvmargs=-Xmx2048M。 欲了解更多信息,请参阅https://docs.gradle.org/current/userguide/build_environment.html 错误:.dex 文件中的方法引用数不能超过 64K。 在https://developer.android.com/tools/building/multidex.html 了解如何解决此问题 :app:transformClassesWithDexForDebug 失败 错误:任务“:app:transformClassesWithDexForDebug”执行失败。 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessException:org.gradle.process。 internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java'' 以非零退出值 2 结束
我的 build.gradle 文件在这里:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "xyz.in.network"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
multiDexEnabled true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(':libs:ViewPagerIndicator')
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.android.gms:play-services-maps:9.0.0'
compile 'com.google.android.gms:play-services-location:9.0.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.gms.google-services'
我的清单文件在这里
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="android.support.multidex.MultiDexApplication"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Util.DisconnectedNetwork"
android:screenOrientation="portrait"
android:theme="@style/Theme.Transparent"></activity>
<service android:name=".FCM.FirebaseMessagingHandler">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".FCM.FirebaseRegistrationTokenHandler">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
将堆大小增加到 2048M 后。 Gradle 报此错误
错误:任务 ':app:transformClassesWithDexForDebug' 执行失败。 com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: 方法 ID 不在 [0, 0xffff] 中: 65536
我按照 android 开发者网站上的所有说明进行操作,但仍然遇到此问题。如何解决这个问题?
【问题讨论】:
-
我认为使用
multidex应该是最后的选择,因为它会使构建过程非常“繁重”。尝试删除一些依赖项:您正在使用compile 'com.google.android.gms:play-services-maps:9.0.0'和compile 'com.google.android.gms:play-services-location:9.0.0',但它们已经包含在compile 'com.google.android.gms:play-services:9.0.0'中。另外,不要加载所有播放服务,因为 google 将其拆分为更小的部分,严格包含您需要的内容
标签: android heap-memory dex android-multidex