I examined the file created when selecting Empty Activity in Android Studio

In Android Studio, when you create a new project from Start a new Android Studio project, the template list is displayed. I often use ʻEmpty Activity`, but I'm grateful that the templates prepare various useful ones from the beginning, but honestly Nanikore? Since there are many files called, I checked it. In short, it's a memorandum.

environment

file organization

One question I wondered is if Java and Kotlin are different from the templates. So I created the Java version as myapplication1 and the Kotlin version as myapplication2.

By the way, com.sirius.software is the package name that I personally use.

configure_your_project.png

The result of expanding all the items created by the template is as follows. The Java version is on the left and the Kotlin version is on the right.

java_kotlin.png

It seems that there is no big difference at first glance, but Only the Kotlin version had an item called generatedJava from the beginning. Even in the Java version, it was displayed as an item when I built it, so I guess the Kotlin version was built once at the beginning.

Files under app

app/manifests/AndroidManifest.xml

Contains information about Android apps. Is it an overview of the app as seen from the Android system? It is likely that you will edit it mainly when adding / changing / deleting activities.

There is no difference in Java / Kotlin. I wrote a comment about the tag and each element (I personally researched it).

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>

<!--
<manifest> AndroidManifest.Root element of xml
・ Xmlns:android =Indicates that it is an xml file for Android
・ Package=Package name
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sirius.software.myapplication1">

    <!--
    <application>Application-wide configuration elements
・ Android:allowBackup =Whether to back up the application data to GoogleDrive etc.
・ Android:icon        =Specify the resource of the app icon
・ Android:label       =Specify the display name of the app
・ Android:roundIcon   = Android 7.Specify the resource of the round icon corresponding to 1 or later
・ Android:supportRtl  =Does it support layouts that display sentences from right to left, such as Arabic?
・ Android:theme       =Specify the default theme for the activity
    -->

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!--
        <activity>Setting elements for each activity
・ Android:name =Activity resource name
        -->

        <activity android:name=".MainActivity">

            <!--
            <intent-filter>Specifies the type of implicit intent that can be processed
For example, this app tells Android systems that it can make phone calls
Android if you want to show.intent.action.Add CALL
            -->

            <intent-filter>
                <!-- .Indicates that MainActivity is displayed when the app is started-->
                <action android:name="android.intent.action.MAIN" />

                <!--Indicates that it can be started from the home icon-->
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

app/java/com.sirius.software.myapplication1/MainActivity.java

Source code for the main activity. Without this, nothing will be displayed when you start the app. The action bar is the title display-like place that appears at the top of the activity.

The Java version requires a semicolon at the end of the line.

MainActivity.java


//Package declaration
package com.sirius.software.myapplication1;

//Required when creating an activity with an action bar
import android.support.v7.app.AppCompatActivity;

//Required to have the Android system manage the status of the activity
import android.os.Bundle;

//Entry point (start here)
public class MainActivity extends AppCompatActivity {

    //onCreate event handler
    //Called when the activity is started
    //Override annotation reuses existing onCreate
    //Convenient because you don't have to write the basic magic of the activity
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        //Call the superclass onCreate
        //savedInstanceState stores the state of the activity
        super.onCreate(savedInstanceState);

        //Load and display the layout file
        setContentView(R.layout.activity_main);
    }
}

app/java/com.sirius.software.myapplication2/MainActivity.kt

This is the main activity of the Kotlin version. No semicolon is needed.

MainActivity.kt


package com.sirius.software.myapplication2

import android.support.v7.app.AppCompatActivity
import android.os.Bundle

//public is omitted and the extends keyword is:Changed to
class MainActivity : AppCompatActivity() {

    //Annotations were omitted and onCreate was refreshing
    // Bundle?Hatena indicates that the value may be Null (nullable)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

app/generatedJava/com.sirius.software.myapplication*/BuildConfig

If you want to separate some processing between Debug build and Release build It seems that you can use it by adding constants and processes to BuildConfig. I will edit it when that time comes.

app/generatedJava/com.sirius.software.myapplication*.test/BuildConfig

Does it mean that the processing can be divided at build time even in unit tests? I'm not sure yet, so I'll look it up at a later date.

app/java/com.sirius.software.myapplication*/ExampleInstrumentedTest.*

A test sample file that can be executed on the actual machine or emulator.

app/java/com.sirius.software.myapplication*/ExampleUnitTest.*

A sample file of tests that can be run on Android Studio + Java Virtual Machine (JVM). There seems to be no explicit rule on how to handle these sample files.

app/res/drawable/ic_launcher_background.xml

Set the background when you create an adaptive icon.

app/res/drawable/ic_launcher_foreground.xml

Set the foreground when you create an adaptive icon. Adaptive icons are a mechanism to align (unify) the shapes of app icons.

app/res/layout/activity_main.xml

The layout of the activity. Arrange the buttons and views displayed on the screen.

activity_main.xml


<?xml version="1.0" encoding="utf-8"?>

<!--
<android.support.constraint.ConstraintLayout>Automatically optimize layout
・ Xmlns:android         =Indicates that it is an xml file for Android
・ Xmlns:app             =Define an XML namespace and make the app attribute available
・ Xmlns:tools           =Define an XML namespace and make the tools attribute available
・ Android:layout_width  =Width adjustment (match)_parent:Display to fill the display area)
・ Android:layout_height =Height adjustment (match)_parent:Display to fill the display area)
・ Tools:context         =Which activity the layout will be used for
-->

<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity">

    <!--
    <TextView>Show label
・ Android:layout_width  =Width adjustment (wrap_content:If it is a character string, match its length)
・ Android:layout_height =Height adjustment (wrap_content:If it is a character string, match its length)
・ Android:text          =Character string to display
・ App:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent"
→ Specify how to arrange itself with respect to adjacent views in automatic layout
    -->

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

app/res/mipmap/ic_launcher/ic_launcher.png

It is a resource (image) file of the application icon. It seems that the following sizes should be prepared for the raster image.

resolution Image size
hdpi 72x72
mdpi 48x48
xhdpi 96x96
xxhdpi 144x144
xxxhdpi 192x192

app/res/mipmap/ic_launcher/ic_launcher.xml

Adaptive icon definition file. The following files are being read. ic_launcher_background.xml ic_launcher_foreground.xml

app/res/mipmap/ic_launcher_round/ic_launcher_round.png

It is a resource (image) file of the round application icon. The only difference from ʻic_launcher.png` is that the shape of the icon is round.

app/res/mipmap/ic_launcher_round/ic_launcher_round.xml

It has the same contents as ʻic_launcher.xml`. This is also just a round icon.

app/res/values/colors.xml

Defines a color name and color code.

colors.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>     <!--Action bar background color-->
    <color name="colorPrimaryDark">#00574B</color> <!--Status bar background color-->
    <color name="colorAccent">#D81B60</color>      <!--Basic color of the control-->
</resources>

app/res/values/strings.xml

Defines the string used in the app. Initially there is only the display name of the app.

strings.xml


<resources>
    <string name="app_name">My Application1</string> <!--App display name-->
</resources>

app/res/values/styles.xml

Set a theme for your app's activities and views. Theme.AppCompat.Light.DarkActionBar is the parent theme, and it seems that you can extend it independently from here.

styles.xml


<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Files under gradle

Gradle is used to build the app. Those who want to use development tools such as data binding and those who want to customize various things seem to edit here. At the moment, I don't think I have a chance to edit it unless there is something special, so I just checked the outline for the time being.

Gradle Scripts/build.gradle

A file that defines build procedures in the language Groovy.

Gradle Scripts/gradle-wrapper.properties

The configuration file needed to run the build in Gradle.

Gradle Scripts/proguard-rules.pro

Definition file to prevent reverse engineering of the app.

Gradle Scripts/gradle.properties

Your own properties file for use with Gradle.

Gradle Scripts/settings.gradle

Specifies which projects to include when building. It will not be used in a single project.

Gradle Scripts/local.properties

It is used to manage textual information that you do not want to keep in the repository. It seems that the settings specific to the development environment correspond to this.

Summary

The files with various roles are prepared from the beginning, and it feels like it's completely exhausted. If you just want to make an app normally, you can edit the following files or add your own.

app/manifests/AndroidManifest.xml app/java/com.sirius.software.myapplication1/MainActivity.java app/java/com.sirius.software.myapplication2/MainActivity.kt app/res/drawable/ic_launcher_background.xml app/res/drawable/ic_launcher_foreground.xml app/res/layout/activity_main.xml app/res/mipmap/ic_launcher/ic_launcher.png app/res/mipmap/ic_launcher_round/ic_launcher_round.png app/res/values/colors.xml app/res/values/strings.xml app/res/values/styles.xml

Recommended Posts

I examined the file created when selecting Empty Activity in Android Studio
3 ways to import the library in Android Studio
Use the JDK used in Android Studio in the terminal
A troublesome story when deleting the gems file created in the gem development directory.
Difficulties when implementing Alarm Manager in Android Studio
I stumbled on the Java version in Android Studio, so I will summarize it
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
I got a cannot resolve symbol in Android Studio
Notes in Android studio
When I switched to IntelliJ, I got a lot of differences in the encoding of the properties file.
The story when the test folder was not created in Rails
Refer to C ++ in the Android Studio module (Java / kotlin)
I tried to make the "Select File" button of the sample application created in the Rails tutorial cool
I got stuck in File
I tried to create a simple map app in Android Studio
The problem that XML attributes are sorted arbitrarily in Android Studio
About what I did when creating a .clj file in Clojure
When I edit the properties file, it looks like garbled characters
[Android] I want to get the listener from the button in ListView