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'

相关推荐
whysqwhw12 分钟前
OkHttp平台抽象机制分析
android
hsx6661 小时前
Android 内存泄漏避坑
android
whysqwhw1 小时前
OkHttp之okhttp-bom模块的分析
android
餐桌上的王子1 小时前
Android 构建可管理生命周期的应用(二)
android
幽你一默2 小时前
Android 版本差异速查表(开发者视角)
android
不萌2 小时前
android 项目中的屏幕适配方案
android
幽你一默2 小时前
Android开发三分钟读懂mvc,mvp,mvvm,mvi
android
木叶丸3 小时前
AI三大核心概念通俗指南:AIGC、Agent、MCP
人工智能·flutter·架构
小仙女喂得猪4 小时前
2025 源码应用: Retrofit之动态更换BaseUrl
android·android studio
AmazingMQ4 小时前
Android 13----在framworks层映射一个物理按键
android