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'

相关推荐
alexhilton15 小时前
Kotlin互斥锁(Mutex):协程的线程安全守护神
android·kotlin·android jetpack
spencer_tseng16 小时前
Eclipse 4.7 ADT (Android Development Tools For Eclipse)
android·java·eclipse
archko18 小时前
android pdf框架-15,mupdf工具与其它
android·pdf
.豆鲨包20 小时前
【Android】MVP架构模式
android·架构
代码会说话21 小时前
i2c通讯
android·linux·嵌入式硬件·嵌入式
程序员老刘21 小时前
为什么我从不推荐GetX?11k星标背后的真相
flutter·客户端
默|笙1 天前
【c++】set和map的封装
android·数据库·c++
kaikaile19951 天前
PHP计算过去一定时间段内日期范围函数
android·开发语言·php
2501_929382651 天前
电视盒子助手开心电视助手 v8.0 删除电视内置软件 电视远程控制ADB去除电视广告
android·windows·adb·开源软件·电视盒子
太过平凡的小蚂蚁1 天前
Kotlin 异步数据流三剑客:Flow、Channel、StateFlow 深度解析
android·kotlin