前言
最近升级Android Studio后,提示gradle也要升级。
Android Studio版本:Android Studio Ladybug Feature Drop | 2024.2.2 Patch 1
Gradle版本:gradle-8.9-bin.zip
gradle-wrapper.properties
#Fri Feb 14 17:49:05 CST 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists #distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip distributionUrl=file:///C:/Users/admin/AndroidT/Gradle/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
我则使用了离线版本,这样更快。
不一定合适其他人遇到的问题,这里只是个人记录哈。
正文
编译老代码。
错误1
Cause: compileSdkVersion is not specified. Please add it to build.gradle
意思没有指定编译版本
修改
在BiuMusic/build.gradle (我这以BiuMusic为例)中新增
// 35可以改成其他的比如 33 34看自己环境 compileSdk 35
错误2
Namespace not specified. Specify a namespace in the module's build file: E:\CaroceanCenter\7870\uis7870-wuling\apps\BiuMusic\build.gradle. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
意思namespace没有指定
修改
在BiuMusic/build.gradle (我这以BiuMusic为例)中新增
namespace 'com.biumall.music'
错误3
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':BiuMusic:compileDebugJavaWithJavac'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:130) at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:293) .... Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details. at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:79) at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:46) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:98) ....
会提示资源ID找不到。
> Task :BiuMusic:compileDebugJavaWithJavac FAILED Java compiler version 21 has deprecated support for compiling with source/target version 8. Try one of the following options: 1. [Recommended] Use Java toolchain with a lower language version 2. Set a higher source/target version 3. Use a lower version of the JDK running the build (if you're not using Java toolchain) For more details on how to configure these settings, see https://developer.android.com/build/jdks. To suppress this warning, set android.javaCompile.suppressSourceTargetDeprecationWarning=true in gradle.properties.
上面有提示在gradle.properties中设置
android.javaCompile.suppressSourceTargetDeprecationWarning=true
修改
找到工程目录下的gradle.properties
添加如下
android.nonFinalResIds=false
完整代码
# Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true # AndroidX package structure to make it clearer which packages are bundled with the # Android operating system, and which are packaged with your app"s APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true # 新增的 android.nonFinalResIds=false
然后编译apk就成功了。
参考文章
© 版权声明