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'

相关推荐
_一条咸鱼_7 小时前
揭秘 Android View 位移原理:源码级深度剖析
android·面试·android jetpack
_一条咸鱼_7 小时前
深度剖析:Android View 滑动原理大揭秘
android·面试·android jetpack
_一条咸鱼_7 小时前
深度揭秘:Android View 滑动冲突原理全解析
android·面试·android jetpack
_一条咸鱼_7 小时前
揭秘 Android View 惯性滑动原理:从源码到实战
android·面试·android jetpack
ansondroider8 小时前
Android adb 安装应用失败(安装次数限制)
android·adb·install
肥肥呀呀呀8 小时前
flutter getx 中.obs 的方法refresh方法
flutter
只可远观8 小时前
Flutter 泛型 泛型方法 泛型类 泛型接口
服务器·windows·flutter
肥肥呀呀呀8 小时前
ipa包安装到apple手机上
flutter
艾小逗9 小时前
uniapp中检查版本,提示升级app,安卓下载apk,ios跳转应用商店
android·ios·uni-app·app升级