1
报错信息
'compileReleaseJavaWithJavac' task (current target is 1.8) and 'compileReleaseKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version
解决方案
android {
//添加
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
//添加
kotlinOptions {
jvmTarget = '17'
}
}
2.
报错信息
You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply
ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/ldd/girlmerry/build/flutter_inappwebview_android/outputs/mapping/release/missing_rules.txt.
ERROR: R8: Missing class android.window.BackEvent (referenced from: void io.flutter.embedding.android.FlutterActivity.startBackGesture(android.window.BackEvent) and 3 other contexts)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':flutter_inappwebview_android:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
> 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 15s
Running Gradle task 'assembleRelease'... 16.0s
Gradle task assembleRelease failed with exit code 1
解决方案
在build.gradle(android)下面配置
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
afterEvaluate { project ->
//解决gradle8.0+namespace编译失败的问题
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
//这里
if (it.name == "flutter_inappwebview_android") {
it.android.buildTypes.release.minifyEnabled = false
}
}
}
3
报错信息
flutter build apk
You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply
ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/ldd/项目名/build/app/outputs/mapping/release/missing_rules.txt.
ERROR: R8: Missing class com.huawei.android.telephony.ServiceStateEx (referenced from: int com.huawei.hms.framework.common.NetworkUtil.getHwNetworkType(android.content.Context))
Missing class com.huawei.hianalytics.process.HiAnalyticsConfig$Builder (referenced from: void com.huawei.hms.utils.HMSBIInitializer$a.onCallBackSuccess(java.lang.String))
Missing class com.huawei.hianalytics.process.HiAnalyticsConfig (referenced from: void com.huawei.hms.utils.HMSBIInitializer$a.onCallBackSuccess(java.lang.String))
Missing class com.huawei.hianalytics.process.HiAnalyticsInstance$Builder (referenced from: void com.huawei.hms.utils.HMSBIInitializer$a.onCallBackSuccess(java.lang.String))
Missing class com.huawei.hianalytics.process.HiAnalyticsInstance (referenced from: com.huawei.hianalytics.process.HiAnalyticsInstance com.huawei.hms.framework.common.hianalytics.HianalyticsHelper.defaultInstance and 14 other contexts)
Missing class com.huawei.hianalytics.process.HiAnalyticsManager (referenced from: void com.huawei.hms.framework.common.hianalytics.HianalyticsHelper.<init>() and 5 other contexts)
Missing class com.huawei.hianalytics.util.HiAnalyticTools (referenced from: void com.huawei.hms.support.hianalytics.HiAnalyticsUtils.enableLog(android.content.Context))
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
> 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 1m 17s
Running Gradle task 'assembleRelease'... 78.3s
Gradle task assembleRelease failed with exit code 1
解决方案 把这里输出的内容复制到app的规则文件中
我这里的路径/Users/ldd/项目名/build/app/outputs/mapping/release/missing_rules.txt
拷贝到proguard-rules.pro 文件末尾解决
4 升级到flutter3.24无法打包的问题
在android/build.gradle下添加
subprojects {
afterEvaluate { project ->
if (project.plugins.hasPlugin("com.android.application") ||
project.plugins.hasPlugin("com.android.library")) {
project.android {
compileSdkVersion 34
buildToolsVersion "34.0.0"
}
}
}
}