无法生成签名 APK
Unable to Generate Signed APK
我的代码在设备上 运行 没问题,但是当我尝试生成签名 APK 时,它开始出错;
Information:Gradle tasks [:assembleRelease]
Error:UNEXPECTED TOP-LEVEL ERROR:
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:Execution failed for task ':transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:
java.lang.UnsupportedOperationException
Information:BUILD FAILED
在我的 Gradle 文件中,唯一导致问题的是这一行,如果我删除这一行,它将生成签名的 APK。
compile 'com.google.android.gms:play-services:9.6.1'
这是我的 Gradle 文件;
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode = 2
versionName = "1.0.2"
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
jni.srcDirs = []
}
instrumentTest.setRoot('tests')
}
signingConfigs {
release
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
// ~/.gradle/gradle.properties
if (project.hasProperty('keystoreFile') &&
project.hasProperty('keystorePassword') &&
project.hasProperty('keystoreAliasPassword')) {
android.signingConfigs.release.storeFile = file(keystoreFile)
android.signingConfigs.release.storePassword = keystorePassword
android.signingConfigs.release.keyPassword = keystoreAliasPassword
android.signingConfigs.release.keyAlias = keystoreAlias
} else {
android.buildTypes.release.signingConfig = null
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services:9.6.1'
}
这些是我项目的 lib 文件夹中的库;
尝试将此行添加到 Project
gradle 文件的末尾。
apply plugin: 'com.google.gms.google-services'
并在 Module gradle
中添加类路径依赖项
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
有一种单独的方法可以提高 dexing 操作的堆限制。将此添加到 build.gradle 文件中的 android 闭包:
dexOptions {
javaMaxHeapSize "4g"
}
看看是否有帮助。
我的代码在设备上 运行 没问题,但是当我尝试生成签名 APK 时,它开始出错;
Information:Gradle tasks [:assembleRelease]
Error:UNEXPECTED TOP-LEVEL ERROR:
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:Execution failed for task ':transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:
java.lang.UnsupportedOperationException
Information:BUILD FAILED
在我的 Gradle 文件中,唯一导致问题的是这一行,如果我删除这一行,它将生成签名的 APK。
compile 'com.google.android.gms:play-services:9.6.1'
这是我的 Gradle 文件;
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode = 2
versionName = "1.0.2"
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
jni.srcDirs = []
}
instrumentTest.setRoot('tests')
}
signingConfigs {
release
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
// ~/.gradle/gradle.properties
if (project.hasProperty('keystoreFile') &&
project.hasProperty('keystorePassword') &&
project.hasProperty('keystoreAliasPassword')) {
android.signingConfigs.release.storeFile = file(keystoreFile)
android.signingConfigs.release.storePassword = keystorePassword
android.signingConfigs.release.keyPassword = keystoreAliasPassword
android.signingConfigs.release.keyAlias = keystoreAlias
} else {
android.buildTypes.release.signingConfig = null
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services:9.6.1'
}
这些是我项目的 lib 文件夹中的库;
尝试将此行添加到 Project
gradle 文件的末尾。
apply plugin: 'com.google.gms.google-services'
并在 Module gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
有一种单独的方法可以提高 dexing 操作的堆限制。将此添加到 build.gradle 文件中的 android 闭包:
dexOptions {
javaMaxHeapSize "4g"
}
看看是否有帮助。