我有两个问题。我无法以任何一种方式构建发行版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堆空间”问题,而他们没有这样做。
答案 0 :(得分:1)
删除行classpath 'com.android.tools:r8:1.5.68'
应该可以解决该问题,因为这将使Android Gradle插件使用其内置的R8版本。
问题是您正在使用R8发行版1.5.68(classpath 'com.android.tools:r8:1.5.68'
)和Android Gradle插件版本3.6.0-alpha09(classpath 'com.android.tools.build:gradle:3.6.0-alpha09'
)。 R8(this CL)的1.6.x版引入了缺少的API。