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'

相关推荐
向哆哆1 小时前
构建跨端健身俱乐部管理系统:Flutter × OpenHarmony 的数据结构与设计解析
数据结构·flutter·鸿蒙·openharmony·开源鸿蒙
不爱吃糖的程序媛2 小时前
Flutter版本选择指南:3.38.10 发布,Flutter-OH何去何从?
flutter
2601_949809592 小时前
flutter_for_openharmony家庭相册app实战+相册详情实现
javascript·flutter·ajax
灰灰勇闯IT2 小时前
Flutter for OpenHarmony:弹窗与对话框(Dialog)—— 构建清晰的上下文交互
flutter·交互
晚霞的不甘2 小时前
Flutter for OpenHarmony从零到一:构建《冰火人》双人合作闯关游戏
android·flutter·游戏·前端框架·全文检索·交互
2601_949833392 小时前
flutter_for_openharmony口腔护理app实战+饮食记录实现
android·javascript·flutter
独自破碎E2 小时前
【滑动窗口+字符计数数组】LCR_014_字符串的排列
android·java·开发语言
stevenzqzq2 小时前
compose 中 align和Arrangement的区别
android·compose
VincentWei953 小时前
Compose:MutableState 和 mutableStateOf
android
jian110583 小时前
Android studio 调试flutter 运行自己的苹果手机上
flutter·智能手机·android studio