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 小时前
【Mysql】我在广州学Mysql 系列——Mysql 性能优化
android·数据库·经验分享·sql·mysql·性能优化·性能
火炎焱燚-3 小时前
Flutter - StatefulWidget (有状态的 Widget) 和 生命周期
flutter
她似晚风般温柔7893 小时前
鸿蒙开发深入浅出04(首页数据渲染、搜索、Stack样式堆叠、Grid布局、shadow阴影)
android·鸿蒙·纯血鸿蒙
l软件定制开发工作室3 小时前
Flutter系列教程之(2)——Dart语言快速入门
flutter
Python私教3 小时前
Flutter屏幕适配终极方案:flutter_screenutil深度解析
flutter
小蜜蜂嗡嗡3 小时前
flutter Column嵌套ListView高度自适应问题
flutter
江上清风山间明月3 小时前
一周掌握Flutter开发--2、状态管理
flutter·getx·riverpod·inheritedwidget·valuenotifier
l软件定制开发工作室3 小时前
Flutter系列教程之(1)——环境配置、创建项目及打包apk
flutter
恋猫de小郭3 小时前
Flutter 上的 Platform 和 UI 线程合并是怎么回事?它会带来什么?
flutter·ui