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'

相关推荐
西西学代码15 小时前
Flutter---右滑显示删除按钮
flutter
似霰16 小时前
传统 Hal 开发笔记4----实现 Hal 模块
android·hal
Android出海16 小时前
Google Play正式出手整治后台耗电应用
android·新媒体运营·产品运营·流量运营·用户运营
Winter_Sun灬16 小时前
CentOS7 交叉编译 ACE+TAO-6.5.13 安卓 arm64-v8a 静态库
android·ace
kirk_wang16 小时前
Flutter app_settings 库在鸿蒙(OHOS)平台的适配实践与解析
flutter·移动开发·跨平台·arkts·鸿蒙
Digitally16 小时前
4种有效方法:如何将音乐从Mac传输到Android
android
CheungChunChiu16 小时前
Android 多媒体体系完整总结
android
小a彤16 小时前
Flutter 原生开发指南
flutter
L、21816 小时前
Flutter + OpenHarmony 全栈实战:打造“鸿蒙智联”智能家居控制中心(系列终章)
flutter·华为·智能手机·electron·智能家居·harmonyos
晓131316 小时前
SQL篇——【MySQL篇:运维】高可用架构搭建(主从、读写分离、分库分表)
android·数据库·mysql