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"//alternatively−justViewModelcompile"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