我最近看到Google I / O会议室持久性库中宣布的新功能与Android上的Sqlite数据库一起使用。我一直在寻找official documentation,我没有找到我应该在我的Android项目中导入我的gradle文件的依赖项。有人可以帮我一把吗?
答案 0 :(得分:41)
可以在the example codelab上找到新架构组件的依赖关系。
根:
element.attributes
适用于房间:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
对于生命周期依赖项:
compile 'android.arch.persistence.room:runtime:1.0.0-alpha1'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha1'
为我们的查询添加Rxjava2对象:
compile 'android.arch.lifecycle:extensions:1.0.0-alpha1'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha1'
测试迁移:
compile 'android.arch.persistence.room:rxjava2:1.0.0-alpha1'
答案 1 :(得分:7)
在您的项目 root var Start = "denver";
var ListOfStops = new[] { "houston", "austin", "tucson" };
var Final = "denver";
var ans = ListOfStops.Prepend(Start).Append(Final).Zip(ListOfStops.Append(Final), (l,r) => (l,r)).Dump();
上,您必须添加Google的maven存储库:
build.gradle
然后在模块的allprojects {
repositories {
jcenter()
maven {
// For Room Persistence Library
url "https://maven.google.com"
}
}
}
上添加:
build.gradle
如果您想在查询结果中使用 RxJava2 compile 'android.arch.persistence.room:runtime:1.0.0-alpha1'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha1'
compile 'android.arch.lifecycle:extensions:1.0.0-alpha1'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha1'
compile 'android.arch.persistence.room:rxjava2:1.0.0-alpha1'
testCompile'android.arch.persistence.room:testing:1.0.0-alpha1'
和Publisher
个对象,请添加此项
Flowable
最后还将此依赖项添加到测试迁移
compile 'android.arch.persistence.room:rxjava2:1.0.0-alpha1'
更新:库仍然标记为 Alpha1 ,所以我想版本号很快就会更新,可能会使用已更新,as definded on the documentation您可以使用此testCompile'android.arch.persistence.room:testing:1.0.0-alpha1'
直到有最终版本可能是一个好主意1.0.+
room 1.1.1
答案 2 :(得分:4)
添加Google Maven存储库 默认情况下,Android Studio项目未配置为访问此存储库。
要将其添加到项目中,请打开项目的build.gradle文件(而不是应用程序或模块的文件)并添加突出显示的行,如下所示:
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
添加架构组件
打开您的应用或模块的build.gradle文件,并添加您需要的工件作为依赖项:
对于Lifecycles,LiveData和ViewModel,请添加:
compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
对于Room,添加:
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
答案 3 :(得分:3)
尝试使用它来编译房间持久性库
implementation 'android.arch.persistence.room:runtime:1.1.1';
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1';
并在root level build gradle中添加它
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
答案 4 :(得分:3)
* Add these in project level gradle
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
ext {
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
archRoomVersion = "1.0.0-alpha1"
}
* Add these in module level gradle dependencies
dependencies {
compile 'android.arch.persistence.room:runtime:' + rootProject.archRoomVersion;
annotationProcessor 'android.arch.persistence.room:compiler:' + rootProject.archRoomVersion;
}
答案 5 :(得分:2)
这适用于最新版本的Android Studio 3.1。
在Gradle Scripts文件夹下, 在项目 build.gradle中,添加:
allprojects {
repositories {
...
maven { url 'https://maven.google.com' }
}
}
在模块 build.gradle中,添加:
dependencies {
...
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}
来源:https://developer.android.com/topic/libraries/architecture/adding-components.html
答案 6 :(得分:2)
打开 build.gradle(Project:projectName)并添加此行(如果不存在)。
这可以访问Google存储库
args = {
'owner': 'airflow',
'start_date': start_date
}
dag = DAG(dag_id = 'test_dag', schedule_interval=None, default_args=args)
y = 0
def LoadYaml(**kwargs):
y = 'df-12345567789'
kwargs['ti'].xcom_push(key='name',value=y)
return True
def CreatePipeLine(**kwargs):
print("I m client")
def ActivatePipeline(client,pipelineId):
print("activated", client, pipelineId)
start_task = DummyOperator(task_id='Start_Task', dag=dag)
LoadYaml_task = ShortCircuitOperator(task_id='LoadYaml_task',provide_context=True,python_callable=LoadYaml,dag=dag)
start_task.set_downstream(LoadYaml_task)
CreatePipeLine_task = ShortCircuitOperator(task_id='CreatePipeLine_task',provide_context=True,python_callable=CreatePipeLine,op_kwargs = {'client' : 'HeyImclient'},dag=dag)
LoadYaml_task.set_downstream(CreatePipeLine_task)
ActivatePipeline_task= ShortCircuitOperator(task_id='ActivatePipeline_task',provide_context=True,python_callable=ActivatePipeline,op_kwargs = {'client' : 'You','pipelineId' : '1234'},dag=dag)
CreatePipeLine_task.set_downstream(ActivatePipeline_task)
下一步打开 build.gradle(Module:app)并将这两行添加到现有依赖项中
对于Java
allprojects {
repositories {
jcenter()
google()
}
}
对于Kotlin
将此行粘贴到应用kotlin插件顶部的依赖项或android范围之外
def room_version = "1.1.0"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
将此行添加到依赖项
apply plugin: 'kotlin-kapt'
要保持最新状态,请访问mvn repository for room
答案 7 :(得分:2)
对于 androidX 和kapt
def room_version = "2.1.0"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
kapt "androidx.room:room-compiler:$room_version"
答案 8 :(得分:1)
当前(2018 02 14)版本
compile 'android.arch.persistence.room:rxjava2:1.1.0-alpha1'
compile 'android.arch.persistence.room:runtime:1.1.0-alpha1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.0-alpha1'
compile 'android.arch.lifecycle:extensions:1.1.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.1.0'
答案 9 :(得分:0)
打开您的项目的build.gradle
文件(不是您的应用或模块的文件)并添加:
allprojects {
repositories {
google()
jcenter()
}
}
打开您的应用或模块的build.gradle
文件,并添加您需要的工件作为依赖项:
dependencies {
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}
答案 10 :(得分:0)
从2019年7月开始,如果您希望将Room与Kotlin,AndroidX,协程或RxJava一起使用,请在下面添加行。
// Room
implementation 'androidx.room:room-runtime:' + rootProject.roomVersion
// For Kotlin use kapt instead of annotationProcessor
kapt 'androidx.room:room-compiler:' + rootProject.roomVersion
// optional - Kotlin Extensions and Coroutines support for Room
implementation 'androidx.room:room-ktx:' + rootProject.roomVersion
// optional - RxJava support for Room
implementation 'androidx.room:room-rxjava2:' + rootProject.roomVersion
答案 11 :(得分:0)
从@Thracian的答案出发,这是我在遵循本文档时要做的事情:
https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/#13
"HT"
还必须在 /* Room */
implementation 'androidx.room:room-runtime:2.1.0'
kapt 'androidx.room:room-runtime:2.1.0'
implementation 'androidx.room:room-compiler:2.1.0'
kapt 'androidx.room:room-compiler:2.1.0'
annotationProcessor 'androidx.room:room-compiler:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha02'
kapt 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha02'
implementation 'androidx.room:room-ktx:2.1.0'
kapt 'androidx.room:room-ktx:2.1.0'
implementation 'android.arch.lifecycle:extensions:1.1.1'
kapt 'android.arch.lifecycle:extensions:1.1.1'
中添加:
android {}
尽管我读过什么,但对于Kotlin,您仍然必须使用 compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
答案 12 :(得分:0)
def room_version = "2.2.3"
def lifecycle_version = "2.1.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" // ViewModel and LiveData
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"