1. 先搞个有REST API的网站
之前用过retrofit1,想用用retrofit2
选了一个之前有搭过的开源web框架“GitLab” https://github.com/gitlabhq/gitlabhq
ubuntu安装参考:https://about.gitlab.com/installation/#ubuntu
浏览器输入自己的IP(或安装gitlab的服务器IP),就能看到自己GitLab
用README里介绍的默认用户名和密码登陆 地址后输入profile/personal_access_tokens,生成个private token,登陆认证时会用到
2. Android客户端
(1)新建工程
Android Studio 3.2
“New”->“NewProject”-> 默认的“Login Activity”
添加dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'net.danlaw:android.joda:2.9.9.2'
implementation 'commons-io:commons-io:2.6'
implementation 'commons-lang:commons-lang:2.6'
implementation 'commons-codec:commons-codec:1.11'
}
(2)REST API 接口
Session类,用来处理登陆 session