在Android Studio中使用Git前需要先登录GitHub账号并建立远程仓库。可按照以下的步骤进行操作:
在GitHub上创建一个仓库,复制仓库地址。
在Android Studio中打开VCS菜单,并选择“Import into Version Control” -> “Share Project on GitHub”。
在弹出的窗口中输入仓库地址和您的GitHub账号和密码。
点击“分享”按钮,您的代码将被上传到GitHub仓库中。
之后,每次push代码前都需要登录GitHub账号。可在Android Studio的右下角找到“Git:”按钮,点击后选择“Configure” -> “Remotes”,然后选择远程仓库并输入GitHub账号密码即可。以下是代码示例:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'com.google.gms.google-services'
id 'com.github.dcendents.android-maven'
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.gitlogin"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test