Android Architecture Components 只看这一篇就够了

1.3、主要架构

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

1.4、使用组件

在项目根目录 build.gradle 文件添加仓库依赖:

allprojects {
repositories {
jcenter()
google()
}
}

如果遇到如下因 gradle 版本导致的编译失败问题:

Error:(6, 1) A problem occurred evaluating root project ‘TestArc’.>
Could not find method google() for arguments [] on repository container;

可修改为:

maven {
url ‘https://maven.google.com’
}

然后在主 module 的 build.gradle 文件添加需要依赖的组件:

dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
androidTestCompile(‘com.android.support.test.espresso:espresso-core:2.2.2’, {
exclude group: ‘com.android.support’, module: ‘support-annotations’
})
compile ‘com.android.support:appcompat-v7:26.+’

def lifecycle_version = “1.1.1”

// ViewModel and LiveData
compile “android.arch.lifecycle:extensions: l i f e c y c l e v e r s i o n " / / a l t e r n a t i v e l y − j u s t V i e w M o d e l c o m p i l e " a n d r o i d . a r c h . l i f e c y c l e : v i e w m o d e l : lifecycle_version" // alternatively - just ViewModel compile "android.arch.lifecycle:viewmodel: lifecycleversion"//alternativelyjustViewModelcompile"android.arch.lifecycle:viewmodel:lifecycle_version” // use -ktx for Kotlin
// alternatively - just LiveData
compile “android.arch.lifecycle:livedata: l i f e c y c l e v e r s i o n

  • 29
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值