gpt4 book ai didi

java - 房间架构导出目录 - 找不到参数的方法 javaCompileOptions()

转载 作者:行者123 更新时间:2023-11-29 22:42:46 24 4
gpt4 key购买 nike

我正在使用 Android 数据库组件室,我想在 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"


}

但是我遇到了以下错误:

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.

这是我的 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;
}
}

这是我的 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
}

我不确定我做错了什么。有人可以建议吗?谢谢!

最佳答案

我相信您需要按照(在 defaultConfig 中)将编译选项移动到 android 选项中:-

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"


}

关于java - 房间架构导出目录 - 找不到参数的方法 javaCompileOptions(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58852475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com