Flutter-Android编译报错与解决方案汇总

报错一:java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null

解决方案:

I solved this problem by upgrading Android Gradle Plugin to version 8.3.1.

You can use Tools->AGP Upgrade Assistant to upgrade Android Gradle plugin.

报错二:Namespace not specified. Specify a namespace in the module's build file.

解决方案:

allprojects {

repositories {

google()

mavenCentral()

}

// This code is where all the magic happens and fixes the error.

subprojects {

afterEvaluate { project ->

if (project.hasProperty('android')) {

project.android {

if (namespace == null) {

namespace project.group

}

}

}

}

}

// This code is where all the magic happens and fixes the error.

}

报错三:Class 'kotlin.Suppress' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

解决方案:

https://stackoverflow.com/questions/67699823/module-was-compiled-with-an-incompatible-version-of-kotlin-the-binary-version-o

The expected version is the Kotlin for kotlin-gradle-plugin

The binary version is what is downloaded (or previously compiled) for com.android.tools.build:gradle

buildscript {

ext.kotlin_version = '1.5.20' // <= expected version is 1.5.1

}

dependencies {

classpath 'com.android.tools.build:gradle:7.3.1' // downloads 1.7.1 Metadata

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // <= 1.5.20 used here

}

KGP、Gradle、AGP版本对应表:https://kotlinlang.org/docs/gradle-configure-project.html#apply-the-plugin

通过差对应表,将主工程下的KGP版本升级即可。

From

ext.kotlin_version = '1.7.10'

to

ext.kotlin_version = '2.0.0'

相关推荐
西西学代码40 分钟前
Flutter---个人信息(5)---持久化存储
java·javascript·flutter
Jerry2 小时前
Compose 的阶段
android
Zhangzy@2 小时前
Rust 编译优化选项
android·开发语言·rust
芝麻开门-新起点2 小时前
Flutter 存储管理:从基础到进阶的完整指南
flutter
星释2 小时前
鸿蒙Flutter三方库适配指南:10.插件测试
flutter·华为·harmonyos
Bryce李小白2 小时前
Flutter boost权威指南
flutter
某空m3 小时前
【Android】View滑动的实现
android
芝麻开门-新起点4 小时前
Android 和 iOS 系统版本及开发适配
android·ios·cocoa
2501_915918415 小时前
iOS描述文件功能解析
android·macos·ios·小程序·uni-app·cocoa·iphone
用户69371750013845 小时前
一文彻底搞懂 Android 依赖配置:implementation vs testImplementation,再也不混淆!
android