Home > OS >  android Jetpack Room Export schemas failed
android Jetpack Room Export schemas failed

Time:01-20

I refer to setting Export schemas in the documentation, But it failed, the error is as follows: enter image description here The following is my Gradle configuration:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'

    // hilt
    id 'kotlin-kapt'
    id 'com.google.dagger.hilt.android'

}

android {
    namespace 'com.freedom.android'
    compileSdk 32

    defaultConfig {
        applicationId "com.freedom.android"
        minSdk 26
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }

        // Room
        javaCompileOptions {
            annotationProcessorOptions {
                compilerArgumentProviders(
                        new RoomSchemaArgProvider(new File(projectDir, "schemas"))
                )
            }
        }
    }

    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.1.1'
    }
    packagingOptions {
        resources {
            excludes  = '/META-INF/{AL2.0,LGPL2.1}'
        }
    }

    applicationVariants.all { variant ->
        variant.getRuntimeConfiguration().exclude group: 'com.google.code.findbugs', module: 'jsr305'
    }
}

dependencies {
    /**
     * Room
     */
    def room_version = "2.4.3"
    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"
    // To use Kotlin annotation processing tool (kapt)
    kapt "androidx.room:room-compiler:$room_version"
    // To use Coroutine features, you must add `ktx` artifact from Room as a dependency. androidx.room:room-ktx:<version>
    implementation "androidx.room:room-ktx:$room_version"



   
    // Could not find method ksp() for arguments [androidx.room:room-compiler:2.4.3] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
    // To use Kotlin Symbol Processing (KSP)
    // ksp "androidx.room:room-compiler:$room_version"

    // hilt
    implementation("com.google.dagger:hilt-android:2.44")
    kapt("com.google.dagger:hilt-android-compiler:2.44")

   
    def lifecycle_viewmodel_version = "2.5.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_viewmodel_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_viewmodel_version"

   
    // private val articleViewModel: ArticleViewModel by viewModels()
    // java.lang.IllegalArgumentException: CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`
    implementation "androidx.fragment:fragment-ktx:1.5.1"

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    implementation "androidx.compose.ui:ui:$compose_ui_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
    implementation 'androidx.compose.material:material:1.1.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    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"
}


// hilt
// Allow references to generated code
kapt {
    correctErrorTypes = true
}

// Room
class RoomSchemaArgProvider implements CommandLineArgumentProvider {

    @InputDirectory
    @PathSensitive(PathSensitivity.RELATIVE)
    File schemaDir

    RoomSchemaArgProvider(File schemaDir) {
        this.schemaDir = schemaDir
    }

    @Override
    Iterable<String> asArguments() {
        // Note: If you're using KSP, you should change the line below to return
        // ["room.schemaLocation=${schemaDir.path}"]
        return ["-Aroom.schemaLocation=${schemaDir.path}"]
    }
}

I am basically sure that it is an error caused by setting Export schemas. When I set exportSchema = false, the program can run normally. Sorry my settings file is a bit messy, but like I said, it works.

CodePudding user response:

Convert string like this:

 return ["-Aroom.schemaLocation=${schemaDir.path}".toString()]

About bug here:

https://github.com/gradle/gradle/issues/4730#

  • Related