运行'flutter build apk'命令时出错



我在构建flutter应用程序的发布版本时遇到了问题。当我运行命令";flutter构建应用程序—无收缩";我在下面得到了这个错误。我尝试过flutter清理、使缓存无效/重新启动、删除.gradle文件夹,但似乎没有任何解决方法。我不知道是什么原因导致了这种情况。

关于如何解决这个问题有什么建议吗?

错误输出

/Users/admin/.gradle/caches/transforms-2/files-2.1/efcc4312065c65c7c7e3232f7c990f31/jetified-firebase-messaging-22.0.0/jars/classes.jar: R8: Type com.google.firebase.iid.FirebaseInstanceIdReceiver is defined multiple times: /Users/admin/.gradle/caches/transforms-2/files-2.1/efcc4312065c65c7c7e3232f7c990f31/jetified-firebase-messaging-22.0.0/jars/classes.jar:com/google/firebase/iid/FirebaseInstanceIdReceiver.class, /Users/admin/.gradle/caches/transforms-2/files-2.1/06de51a56b776cd4fc647c005c2b7e7b/firebase-iid-21.0.1/jars/classes.jar:com/google/firebase/iid/FirebaseInstanceIdReceiver.class
  
FAILURE: Build failed with an exception.                                
  
* What went wrong:                                                      
Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete
  
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  
* Get more help at https://help.gradle.org                              
  
BUILD FAILED in 2m 3s                                                   
Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                     124.3s
[!] The shrinker may have failed to optimize the Java bytecode.
To disable the shrinker, pass the `--no-shrink` flag to this command.
To learn more, see: https://developer.android.com/studio/build/shrink-code

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.******"
minSdkVersion 20
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.material:material:1.3.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//    testImplementation 'junit:junit:4.12'
//    androidTestImplementation 'androidx.test:runner:1.2.0' // 1.1.1
//    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' // 3.1.1
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:26.3.0')
// Add the dependency for the Firebase SDK for Google Analytics
// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics'
// implementation "com.google.firebase:firebase-messaging"
// Add the dependencies for any other desired Firebase products
// https://firebase.google.com/docs/android/setup#available-libraries
// Declare the dependency for the Firebase Authentication library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'androidx.browser:browser:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply plugin: 'com.google.gms.google-services'

android/build.gradle

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:3.5.0' // 3.5.0
classpath 'com.google.gms:google-services:4.3.4' // 4.3.2
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}

/gradlew assemblyRelease--信息

* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
AAPT2 aapt2-3.5.0-5435860-osx Daemon #9: shutdown
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 5m 9s
AAPT2 aapt2-3.5.0-5435860-osx Daemon #10: shutdown
509 actionable tasks: 508 executed, 1 up-to-date
AAPT2 aapt2-3.5.0-5435860-osx Daemon #11: shutdown

解决方案

我真的不确定是什么导致了这个问题,但似乎是key.properties文件出了问题。我删除了生成的上传密钥库.jks文件并重新生成了它。之后,我更改了gradle版本如下:

安卓系统->渐变->包装器->渐变包装器.属性

这个文件应该是这样的:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip

我将这个文件和gradle版本编辑为:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-5.6.4-all.zip

相关内容

  • 没有找到相关文章

最新更新