I am using Android Database Component Room and I want to export the schema using the following code in my dependencies in App Gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
javaCompileOptions{
annotationProcessorOptions{
arguments= ["room.schemaLocation":
"$projectDir/schemas".toString()]
}}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.appcompat:appcompat:1.0.0'
//room
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
}
However i am facing the following error:
ERROR: Could not find method javaCompileOptions() for arguments [build_ao1pt454otpr48gba8f3r0tu$_run_closure1$_closure4@53308877] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.
This is my code for AppDatabase:
package com.example.myapplication.database;
import android.content.Context;
import android.util.Log;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import com.example.myapplication.model.DataItem;
//Database which list the entities in database and the DAO
@Database(entities = {DataItem.class}, version = 1, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
private static final String LOG_TAG = AppDatabase.class.getSimpleName();
private static final Object LOCK = new Object();
private static final String DATABASE_NAME = "Datalist";
private static AppDatabase sInstance;
public static AppDatabase getInstance(Context context) {
if (sInstance == null) {
synchronized (LOCK) {
Log.d(LOG_TAG, "Creating new database instance");
sInstance = Room.databaseBuilder(context.getApplicationContext(),
AppDatabase.class, AppDatabase.DATABASE_NAME)
.build();
}
}
Log.d(LOG_TAG, "Getting the database instance");
return sInstance;
}
public abstract DataDao dataItemDao();
public static void destroyAppDatabase(){
sInstance = null;
}
}
This is my Project Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I am not sure what I did wrong. Can anyone please advise? Thank you!