Wie Sie wissen, gibt es in Android Studio zwei Möglichkeiten, mit Git zu arbeiten.
Der erste klassische Weg ist die Verwendung der Konsole. Der Vorteil dieses Ansatzes ist vor allem die ZuverlÀssigkeit. Die GUI kann stecken bleiben und beispielsweise in der Rebase-Phase einfrieren, sodass das Abbrechen / Fortfahren / Wechseln zu einem anderen Zweig nicht hilft. Konsolenbefehle helfen Ihnen, sie sind immer problemlos.
Die zweite Möglichkeit besteht darin, die von Android Studio bereitgestellte BenutzeroberflĂ€che zu verwenden. Die Vorteile liegen auf der Hand - bei einer niedrigeren Einstiegsschwelle ist klarer, was ĂŒberhaupt getan werden kann. AuĂerdem gibt es verschiedene Brötchen aus dem Studio, um bequem mit Git arbeiten zu können. Einer von ihnen wird diskutiert. Ăber die GUI können Sie ĂŒbrigens auch die Maus in Ruhe lassen und den Hotkey verwenden
Im Artikel verwendete Hotkeys
Umschalt + Umschalt (Doppelklick-Umschalt) - Suchfenster. Ermöglicht die Suche nach Code / Ressourcen sowie nach verschiedenen Aktionen und Einstellungen.
Strg + Alt + L (â + â„ + L) -> Code-Formatierung
Umschalt + Strg + Alt + L (â§ + â + â„ + L) â Code-Formatierung â Code-Formatierung mit Parametern.
Worum geht es und wo ist es zu finden?
, , â , , pull request. , hotkey Ctrl+Alt+L, .
Idea/AndroidStudio ,
commit' Android Studio :

, , Before Commit. ,
?
â Reformat code
code style. ctrl+shift+alt+L clean up.
code style Settings â Editor â Code Style
Wendet den Zeileneinzug gemÀà dem Codestil an (Einzelheiten finden Sie unter Codestil im gleichnamigen Abschnitt).
Im Beispiel werden die zur Bildung der EinrĂŒckung verwendeten Leerzeichen (mit Punkten markiert) durch Tabulatoren (mit einem Pfeil markiert) ersetzt.
Vor dem Festschreiben
class CleanTab(context: Context) {
....val date = Date()
....val button = Button(context)
....val textView = TextView(context)
....val ratingBar = RatingBar(context)
....val imageView = ImageView(context)
}
Nach dem Festschreiben
class CleanTab(context: Context) {
-> val date = Date()
-> val button = Button(context)
-> val textView = TextView(context)
-> val ratingBar = RatingBar(context)
-> val imageView = ImageView(context)
}code-style.
Date, button =, args main {
class CleanSpaces(context:Context) {
val date = Date( )
val button= Button(context)
fun main(arg: Args){
}
}
class CleanSpaces(context: Context) {
val date = Date()
val button = Button(context)
fun main(arg: Args) {
}
}. , / .
else, catch , ( code style)
manyArguments 80 ( code style),
class CleanWrappingAndBraces {
fun condition() {
if (liveData != null) {
<..>
}
else {
<..>
}
}
fun catching() {
try {
<..>
}
catch (e: Exception) {
<..>
}
}
fun manyArguments(userId: Int, issuerCountryId: String, sendingCountryId: String, receivingCountryId: String) {
}
}
class CleanWrappingAndBraces {
fun condition() {
if (liveData != null) {
<..>
} else {
<..>
}
}
fun catching() {
try {
<..>
} catch (e: Exception) {
<..>
}
}
fun manyArguments(userId: Int, issuerCountryId: String,
sendingCountryId: String,
receivingCountryId: String) {
}. ( Code Style, )
}, 2
class CleanBlank {
fun foo() {
}
fun bar() {
}
}
class CleanBlank {
fun foo() {
}
fun bar() {
}
}Rearrange code
, -. XML HTML . Setting â Editor â CodeStyle â XML/HTML â Arrangement
! . Rearrange , , . : LinearLayout, , Button TextView, . â
xmlns , code-style(xmlns:android , xmlns:<...> .
, xmlns:tools xmlns:app , . , rearrange
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools" android:layout_height="match_parent"
android:orientation="vertical" xmlns:app="http://schemas.android.com/apk/res-auto">
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>android:padding code-style. style android:id
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
tools:srcCompat="@tools:sample/avatars" />
<TextView
style="@style/TextAppearance.MaterialComponents.Body1"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:paddingBottom="8dp"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/title"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World" />
</LinearLayout>Optimize import
, code style. ctrl+shift+alt+L optimize import.
optimize imports import java.util.* , ,
import android.content.Context
import android.widget.Button
import java.util.*
class RemoveUnused(context: Context) {
val button = Button(context)
}
import android.content.Context
import android.widget.Button
class RemoveUnused(context: Context) {
val button = Button(context)
} n , .
m enum java static ,
Settings â Editor â Code Style â Kotlin â Imports
android.widget android.widget.*
import android.content.Context
import android.widget.Button
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import android.widget.RatingBar
import java.util.*
class MergeImport(context: Context) {
<..>
}
import android.content.Context
import android.widget.*
import java.util.*
class MergeImport(context: Context) {
<..>
}
, (m = 0, n=0), ( ) // .
import android.widget. import java.util.
import android.content.Context
import android.widget.*
import java.util.*
class MergeImport(context: Context) {
<..>
import android.content.Context
import android.widget.Button
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import android.widget.RatingBar
import java.util.*
class MergeImport(context: Context) {
<..>
}, ,
import android.content.Context
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import java.util.*
import android.widget.RatingBar
class SortImport(context: Context) {
<..>
}
import android.content.Context
import android.widget.Button
import android.widget.ImageView
import android.widget.RatingBar
import android.widget.TextView
import java.util.*
class SortImport(context: Context) {
<..>
}Perform code analysis
. . â , , , Deprecated
fun TextView.format(message: String) {
val htmlText = Html.fromHtml(message)
}
, :

Review :

Check TODO
, TODO, . , //TODO, //FIXME, todo, Setting â Editor â TODO.
todo, .

Clean up
. (. ), deprecated . Actions â Code cleanup. , .
:
- deprecated ( )
- view
! , !
-, .. non-nullable
data class User(val firstName: String, val secondName: String)
val user = User("", "")
fun getUserFullName(): String {
val firstName = user?.firstName
val secondName = user.secondName ?: return firstName
return "$firstName $secondName"
}
data class User(val firstName: String, val secondName: String)
val user = User("", "")
fun getUserFullName(): String {
val firstName = user.firstName
val secondName = user.secondName
return "$firstName $secondName"
}
public, ..
data class User(val firstName: String, val secondName: String)
val user = User("", "")
public fun getUserFullName(): String {
val firstName = user.firstName
val secondName = user.secondName
return "$firstName $secondName"
}
data class User(val firstName: String, val secondName: String)
val user = User("", "")
fun getUserFullName(): String {
val firstName = user.firstName
val secondName = user.secondName
return "$firstName $secondName"
}
class ExecutionClass(val exec: () -> Unit)
val exec = ExecutionClass() {
doIt()
}
class ExecutionClass(val exec: () -> Unit)
val exec = ExecutionClass {
doIt()
}deprecated ReplaceWith(), cleanup . , â , ReplaceWith(). . / . / , ( ), , , . ,
@Deprecated(" ", ReplaceWith("newMethod()"))
fun oldMethod() = Unit
fun newMethod() = Unit
@Deprecated(" ", ReplaceWith("NewClass"))
class OldClass
class NewClass
class GetDeprecatedCodeUseCase(val clazz: OldClass) {
init {
val initData = oldMethod()
}
}
@Deprecated(" ", ReplaceWith("newMethod()"))
fun oldMethod() = Unit
fun newMethod() = Unit
@Deprecated(" ", ReplaceWith("NewClass"))
class OldClass
class NewClass
class GetDeprecatedCodeUseCase(val clazz: NewClass) {
init {
val initData = newMethod()
}
}, Android Studio . , , , . , .
:
Optimize import Reformat code . .
Rearrange Clean up . , - , (Rearrange) (Clean up)
ĂberprĂŒfen Sie TODO und fĂŒhren Sie eine Codeanalyse durch. Sie können auch furchtlos verwendet werden. Sie beeinflussen den Code in keiner Weise, sie geben nur nervige Hinweise. Ja, wenn alles in Ihrem Projekt vollstĂ€ndig auf TODO und veraltetem Code basiert, werden sie kein Ende haben und sie werden Ă€rgerlicher. Wenn Sie jedoch einen ziemlich sauberen Code in Ihrem Projekt haben und versuchen, solche Momente zu minimieren, bieten die Helfer eine hervorragende Möglichkeit, den Code zu ĂŒberarbeiten, wenn Sie eine Auslassung hĂ€tten vornehmen können.