错误信息:
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ‘:app:lintVitalRelease’. Could not resolve all artifacts for configuration ‘:app:debugRuntimeClasspath’. Failed to transform libs.jar to match attributes {artifactType=processed-jar, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. Execution failed for JetifyTransform: /Users/apple/Documents/project/flutter/private/yousi_teacher/build/app/intermediates/flutter/debug/libs.jar. Transform’s input file does not exist: /Users/apple/Documents/project/flutter/private/yousi_teacher/build/app/intermediates/flutter/debug/libs.jar. (See https://issuetracker.google.com/issues/158753935) - 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
在运行 flutter build apk 的时候报错,只有打包 release 版本才会出现错误,debug可以正常运行。 百度了一种解决方案是在 android 里 app 目录下的 build.gradle 中
android {
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
abortOnError false
}
}
添加 checkReleaseBuilds 和 abortOnError 这样设置完虽然可以正常打包,但是 app 安装完打开就崩溃。所以这种方法并不能从根本上解决问题。
尝试第二种方案:
修改 build.gradle
buildscript {
repositories {
// google()
// jcenter()
maven { url'https://maven.aliyun.com/repository/google'}
maven { url'https://maven.aliyun.com/repository/jcenter'}
maven { url'http://maven.aliyun.com/nexus/content/groups/public'}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
还是失败
升级 gradle 版本到 7.0
还是失败
在 app/build.gradle 关闭混淆
android {
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
//是否开启混淆,开启需要设置混淆
minifyEnabled false
//移除无用资源
shrinkResources flase
//混淆文件配置
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
也不行 降级 gradle 到 5.1.1。在 gradle/wrapper/gradle-wrapper.properties 中修改
#Fri Sep 03 12:29:01 CST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
同时降级 tool.build.gradle 到3.4.2。在 android/build.gradle 修改
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
打包成功,安装运行也没问题。
于是去打包另外一个项目,又出现
- What went wrong:
Execution failed for task ‘:alipay_kit:processVendorReleaseManifest’. Manifest merger failed with multiple errors, see logs
因为错误提到了 multiple ,猜想可能需要开启 multiDex 在 app/build.gradle 中的 defaultConfig 里配置,同时 dependencies 引入依赖
android {
defaultConfig {
.....
multiDexEnabled true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.android.support:multidex:1.0.3'
}
打包报错,说明不是这的问题,再看错误日志
Users/apple/Documents/project/flutter/sdk/flutter/.pub-cache/hosted/pub.flutter-io.cn/alipay_kit-2.0.0/android/src/vendor/AndroidManifest.xml:6:9-63 Error: Missing ‘package’ key attribute on element package at AndroidManifest.xml:6:9-63 /Users/apple/Documents/project/flutter/sdk/flutter/.pub-cache/hosted/pub.flutter-io.cn/alipay_kit-2.0.0/android/src/vendor/AndroidManifest.xml Error: Validation failed, exiting FAILURE: Build failed with an exception.
点击查看报错文件 AndroidManifest 发现
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.v7lin.alipay_kit">
<queries>
<!-- targetSdkVersion>=30 -> Android 11 软件包可见性 -->
<package android:name="com.eg.android.AlipayGphone" />
</queries>
</manifest>
根据提示将targetSdkVersion 值和 compileSdkVersion 值设置 >=30 打包依然报错,那就只能去看插件了 文档没问题,去 issus 搜 AndroidManifest 找到了一个关闭的问题,说明不止我遇到了
buildscript {
dependencies {
// Android 11兼容,需升级Gradle到3.5.4/3.6.4/4.x.y
classpath 'com.android.tools.build:gradle:3.5.4'
}
}
别忘了把 gradle version 也升级 到 5.4.1。
构建成功
|