Java 运行时出错';颤振构建apk';命令

Java 运行时出错';颤振构建apk';命令,java,android,flutter,dart,Java,Android,Flutter,Dart,我在为颤振应用程序构建发布版本时遇到问题。当我运行命令“flatterbuildapp--no-shrink”时,我在下面得到了这个错误。我尝试过使用flutter clean、使缓存无效/重新启动、删除.gradle文件夹,但似乎没有任何解决方法。我不知道是什么原因造成的 关于如何解决这个问题有什么建议吗 错误输出 /Users/admin/.gradle/caches/transforms-2/files-2.1/efcc4312065c65c7c7e3232f7c990f31/jetifi

我在为颤振应用程序构建发布版本时遇到问题。当我运行命令“flatterbuildapp--no-shrink”时,我在下面得到了这个错误。我尝试过使用flutter clean、使缓存无效/重新启动、删除.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'
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
}
android/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'
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 assemblererelease--info

* 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文件有问题。我删除了生成的upload-keystore.jks文件并重新生成了它。之后,我对gradle版本进行了如下更改:

android->gradle->wrapper->gradle-wrapper.properties

此文件应如下所示:

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版本编辑为(同时替换upload keystore.jks):


试着在android文件夹中运行
/gradlew assemblererelease--info
,看看到底是哪个异常。我添加了输出,并且gradle-wrapper.properties似乎有问题?我应该把它更新到7.0吗?我尝试了不同版本的cradle-wrapper.properties,但似乎没有任何效果。。。