我使用jetpack comort和kotlin,当我同步依赖并运行应用程序后添加新的依赖项(我不知道哪个会导致错误)时,错误如下,我不知道为什么
执行com.android.build时发生故障kotlin-stdlib-1.8.0模块kotlin-stdlib-1.8.0和kotlin-stdlib-jdk8-1.7.10模块kotlin-stdlib-1.8.0模块kotlin-stdlib-1.8.0 kotlin: kotlin-stdlib:1.8.0 kotlin-stdlib-jdk8-1.7.10 kotlin-stdlib-jdk8-1.7.10
我不知道为什么会出现这个错误。这是我运行应用程序时的错误。
这是我的模块级别依赖:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'com.google.dagger.hilt.android'
id 'com.google.gms.google-services'
}
android {
namespace 'com.haristudio.pdi_app'
compileSdk 33
defaultConfig {
applicationId "com.haristudio.pdi_app"
minSdk 23
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_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.2.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "com.google.accompanist:accompanist-systemuicontroller:0.27.0"
// Jetpack Compose
def compose_version = "1.2.0"
def kotlin_coroutines_version = "1.6.4"
def dagger_version = "2.44.2"
def compose_latest = "1.3.3"
implementation 'androidx.activity:activity-compose:1.6.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_latest"
implementation 'androidx.compose.material:material:1.3.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_latest"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_latest"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_latest"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation "androidx.navigation:navigation-compose:2.5.3"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
implementation 'androidx.compose.material:material-icons-extended:1.3.1'
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
implementation "androidx.compose.runtime:runtime-livedata:1.3.3"
implementation "androidx.compose.foundation:foundation:1.4.0-beta01"
implementation "androidx.compose.runtime:runtime-rxjava2:1.4.0-beta01"
//coil for images
implementation "io.coil-kt:coil-compose:2.2.2"
// exoPlayer
implementation 'com.google.android.exoplayer:exoplayer:2.18.2'
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
// Dagger Hilt
implementation "com.google.dagger:hilt-android:$dagger_version"
kapt "com.google.dagger:hilt-compiler:$dagger_version"
// Firebase
implementation platform('com.google.firebase:firebase-bom:31.2.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation "com.google.firebase:firebase-auth:21.1.0"
implementation 'com.google.firebase:firebase-database:20.1.0'
}
这是我的项目级别依赖
buildscript {
ext {
compose_ui_version = '1.2.0'
}
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
id 'com.google.dagger.hilt.android' version '2.42' apply false
id 'com.google.gms.google-services' version '4.3.14' apply false
}
这是我的autoViewModel
@HiltViewModel
class AuthViewModel @Inject constructor(
private val repository : AuthRepository,
) : ViewModel() {
private val _loginFlow = MutableStateFlow<Resource<FirebaseUser>?>(null)
private val _signUpFlow = MutableStateFlow<Resource<FirebaseUser>?>(null)
val loginFlow: StateFlow<Resource<FirebaseUser>?> = _loginFlow
val signUpFlow: StateFlow<Resource<FirebaseUser>?> = _signUpFlow
private val currentUser : FirebaseUser?
get() = repository.currentUser
init {
if(currentUser != null){
_loginFlow.value = Resource.Success(currentUser!!)
}
}
fun login(email : String, password : String) = viewModelScope.launch {
_loginFlow.value = Resource.Loading
val result = repository.login(email,password)
_loginFlow.value = result
}
fun signUp(
username : String,
email : String,
password : String,
numberPhone : String,
image : String = "null",
navController: NavController
) = viewModelScope.launch {
_signUpFlow.value = Resource.Loading
val result = repository.signUp(username,email,password,image,numberPhone)
_signUpFlow.value = result
if (result is Resource.Success) {
navController.navigate("addNewTeam_screen")
}
}
fun logout(){
repository.logout()
_loginFlow.value = null
_signUpFlow.value = null
}
}
这是我的真迹
class AuthRepositoryImpl @Inject constructor(
private val firebaseAuth: FirebaseAuth
) : AuthRepository {
override val currentUser: FirebaseUser?
get() = firebaseAuth.currentUser
override suspend fun login(
email: String,
password: String
): Resource<FirebaseUser> {
return try {
val result = firebaseAuth.signInWithEmailAndPassword(email,password).await()
Resource.Success(result.user!!)
}catch (e : Exception){
Resource.Failure(exception = e)
}
}
override suspend fun signUp(
username: String,
email: String,
password: String,
image: String,
numberPhone: String
): Resource<FirebaseUser> {
return try {
val result = firebaseAuth.createUserWithEmailAndPassword(email, password).await()
result?.
user?.
updateProfile(
UserProfileChangeRequest
.Builder()
.setDisplayName(username)
.build()
)?.await()
Resource.Success(result.user!!)
}catch (e : Exception){
Resource.Failure(exception = e)
}
}
override fun logout() {
firebaseAuth.signOut()
}
}
这是因为您的一个依赖项已经在使用静态编程语言1.8,而您的项目仍在使用1.7。
如果您无法确定它是哪个依赖项,您可以升级您的项目以使用静态编程语言1.8。这样做应该是安全的,因为没有重大的重大更改(请参阅静态编程语言1.8.0发行说明和兼容性指南)。
buildscript {
dependencies {
// ...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
}
}
plugins {
// ...
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
// ...
}
尝试将kotlin android插件更新到1.8
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false // change this to 1.8.0
id 'com.google.dagger.hilt.android' version '2.42' apply false
id 'com.google.gms.google-services' version '4.3.14' apply false
}
如果在最新的android工作室上,您不需要更改类路径