我有两个问题。无论哪种方式,我都无法构建发布 apk。当我禁用 R8(首选 proguard)时,构建会永远持续下去(有时会崩溃,引用“内存不足:java 堆空间”),当我启用 R8 时,会出现以下错误:
Unable to find method 'com.android.tools.r8.CompatProguardCommandBuilder.setProguardSeedsConsumer(Lcom/android/tools/r8/StringConsumer;)Lcom/android/tools/r8/R8Command$Builder;'.
我的项目级 build.gradle:
buildscript {
repositories {
google()
mavenLocal()
jcenter()
maven { url "https://maven.google.com" }
maven { url 'http://storage.googleapis.com/r8-releases/raw' }
}
dependencies {
classpath 'com.android.tools:r8:1.5.68'
classpath 'com.android.tools.build:gradle:3.6.0-alpha09'
classpath 'com.google.gms:google-services:4.3.1'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.7.3'
}
}
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
}
repositories {
google()
mavenLocal()
jcenter()
maven { url "https://maven.google.com" }
}
apply plugin: "com.jfrog.artifactory"
}
task clean(type: Delete) {
delete rootProject.buildDir
}
还有我的项目模块 build.gradle:
apply plugin: 'com.android.application'
android {
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
}
compileSdkVersion 29
buildToolsVersion '29.0.2'
defaultConfig {
applicationId "XXX"
minSdkVersion 19
targetSdkVersion 29
vectorDrawables.useSupportLibrary = true
signingConfig signingConfigs.release
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles 'proguard.cfg'
}
}
productFlavors {}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
ignoreWarnings true // false by default
quiet true // false by default
abortOnError false
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
api project(':Tableview')
implementation 'com.diogobernardino:williamchart:2.5.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.squareup.okhttp3:okhttp:4.1.0'
implementation 'com.squareup.okio:okio:2.4.0'
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta03'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.emoji:emoji:1.0.0'
implementation 'androidx.exifinterface:exifinterface:1.0.0'
implementation 'androidx.media:media:1.1.0-rc01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.fasterxml.jackson.core:jackson-core:2.10.0.pr1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.10.0.pr1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.0.pr1'
implementation 'commons-io:commons-io:2.6'
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'org.apache.commons:commons-text:1.6'
implementation 'petrov.kristiyan:colorpicker-library:1.1.10'
implementation 'com.google.android.libraries.places:places:2.0.0'
}
apply plugin: 'com.google.gms.google-services'
gradle.properties:
android.enableJetifier=true
artifactory_user=admin
android.useAndroidX=true
android.enableBuildCache=true
org.gradle.jvmargs=-Xmx1g
jvmargs 和 dexOptions 堆大小都被放在那里,试图解决“java 堆空间”问题,但他们没有。