[英]Flutter Android Build Failed : com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Been trying for days;尝试了好几天; googling and trying all sorts of 'fixes' and 'dependencies' etc but still not able to build APK for release.
谷歌搜索并尝试各种“修复”和“依赖项”等,但仍然无法构建用于发布的 APK。 Debug is ok.
调试没问题。
My command: flutter build apk --release error: AILURE: Build failed with an exception.我的命令:flutter build apk --release error: AILURE: Build failed with an exception。
com.android.tools.r8.CompilationFailedException: Compilation failed to complete
com.android.tools.r8.CompilationFailedException:编译未能完成
BUILD FAILED in 2m 1s在 2m 1s 内构建失败
Running Gradle task 'assembleRelease'...运行 Gradle 任务“assembleRelease”...
Running Gradle task 'assembleRelease'... Done 147.3s (.) [,] The shrinker may have failed to optimize the Java bytecode.运行 Gradle 任务 'assembleRelease'... 完成 147.3s (.) [,] 收缩器可能未能优化 Java 字节码。 To disable the shrinker, pass the
--no-shrink
flag to this command.要禁用收缩器,请将
--no-shrink
标志传递给此命令。 To learn more, see: https://developer.android.com/studio/build/shrink-code Gradle task assembleRelease failed with exit code 1要了解更多信息,请参阅: https://developer.android.com/studio/build/shrink-code Gradle task assembleRelease failed with exit code 1
build.grade (app): build.grade(应用程序):
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.")
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'4
throw new GradleException("versionName not found. Define flutter.versionName in the local.properties file.")
}
apply plugin: 'com.android.application'
// 20/2/20
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
// 20/2/20
apply plugin: 'com.google.gms.google-services'
// Add the Fabric plugin. 10 March 2020
apply plugin: 'io.fabric'
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
def kotlin_version = '1.3.21'
android {
compileSdkVersion 28
// 20/2/20
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "net.hotsource.peribuddy"
minSdkVersion 24
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
//testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
minifyEnabled true
//shrinkResources true
//useProguard true
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
debug {
// minifyEnabled true
}
}
}
flutter {
source '../..'
}
dependencies {
// 28 May 2019
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0' // 1.0.2
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
implementation 'com.android.support:multidex:1.0.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
// 10 March 2020
// (Recommended) Add the Google Analytics dependency.
implementation 'com.google.firebase:firebase-analytics:17.4.2' // 17.2.3
// Add the Firebase Crashlytics dependency.
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.firebase:firebase-messaging:20.2.0'
implementation "com.android.support:support-v4:28.0.0"
implementation "com.android.support:support-fragment:28.0.0"
implementation 'com.google.firebase:firebase-firestore:21.4.3'
implementation 'com.google.firebase:firebase-firestore-ktx:21.4.3'
}
// firebase_crashlytics
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
build.gradle (project): build.gradle(项目):
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
// For Crashlytics SDK
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools:r8:1.6.84' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:3.4.2' // 3.1.2 3.3.0-alpha13 4.10.2 330 3.3.2 3.6.3
// classpath 'com.google.gms:google-services:4.2.0' // 3.2.1 4.0.1 4.1.0 4.3.3
classpath 'com.google.gms:google-services:4.2.0'
// Add the Fabric Crashlytics plugin. 10 march 2020 1.31.2
classpath 'io.fabric.tools:gradle:1.31.2'
//classpath 'io.fabric.tools:gradle:1.+' // new
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Add fabric classpath
//classpath 'io.fabric.tools:gradle:1.26.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
configurations.matching { it.name == '_internal_aapt2_binary' }.all { config ->
config.resolutionStrategy.eachDependency { details ->
details.useVersion("3.5.0-alpha03-5252756")
}
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
face the similar issue.面临类似的问题。 what I did is just disable R8.
我所做的只是禁用 R8。 as in your terminal:
就像在您的终端中一样:
flutter build apk --no-shrink
or in your app level build.gradle:或在您的应用程序级别 build.gradle:
minifyEnabled false
shrinkResources false
then build apk as normal然后正常构建apk
by the way, my apk works without R8, because I don't know how to stop it deleting my files顺便说一句,我的 apk 在没有 R8 的情况下工作,因为我不知道如何阻止它删除我的文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.