Android应用可调试运行但assembleDebug编译APK失败报错
编译APK时触发Unsupported class file major version 67错误
应用在Android Studio中点击Run 'app'按钮可在真机和模拟器正常运行,无Bug,但执行./gradlew assembleDebug命令编译生成APK时出现以下错误:
FAILURE: Build failed with an exception. * What went wrong: BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 67 > Unsupported class file major version 67 * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. BUILD FAILED in 274ms
已尝试清理项目并重新构建,删除项目内的.idea和.gradle文件夹、Gradle缓存文件夹,甚至删除~/.gradle文件夹,但问题仍未解决。当前Java版本通过GRADLE_LOCAL_JAVA_HOME设置为JetBrains Runtime 17.0.11 aarch64,路径为/Applications/Android Studio.app/Contents/jbr/Contents/Home。
以下是项目相关配置文件:
gradle.properties
#Mon Oct 14 16:52:43 CEST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
app模块build.gradle
plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'com.google.dagger.hilt.android' id 'com.google.devtools.ksp' } android { namespace 'com.user.project' compileSdk 34 defaultConfig { applicationId "com.user.project" minSdk 28 targetSdk 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary true } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = '17' } buildFeatures { compose true } composeOptions { kotlinCompilerExtensionVersion '1.5.15' } packagingOptions { resources { excludes += '/META-INF/{AL2.0,LGPL2.1}' } } } dependencies { implementation 'androidx.core:core-ktx:1.13.1' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.6' implementation 'androidx.activity:activity-compose:1.9.2' implementation "androidx.compose.ui:ui:$compose_ui_version" implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version" implementation 'androidx.compose.material:material:1.7.3' implementation "com.google.dagger:hilt-android:2.44" implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1" implementation "androidx.navigation:navigation-compose:2.8.2" implementation "androidx.hilt:hilt-navigation-compose:1.2.0" implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.6' implementation 'com.unboundid:unboundid-ldapsdk:6.0.7' implementation "androidx.compose.material:material-icons-extended:$compose_ui_version" implementation fileTree(dir: "libs", include: ['*.aar']) testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.2.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version" debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version" debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version" ksp "com.google.dagger:hilt-android-testing:2.42" ksp "com.google.dagger:hilt-compiler:2.48" }
项目根目录build.gradle
buildscript { ext { compose_ui_version = '1.7.3' } }// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '8.6.1' apply false id 'com.android.library' version '8.6.1' apply false id 'org.jetbrains.kotlin.android' version '1.9.25' apply false id 'com.google.dagger.hilt.android' version '2.48' apply false id 'com.google.devtools.ksp' version '1.9.25-1.0.20' apply false }
settings.gradle
pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } rootProject.name = "MCx Contacts" include ':app'
内容的提问来源于stack exchange,提问作者Chris Pi
相关产品推荐
相关产品推荐

