[JAVA] I tried to take a look at the flow of Android development environment construction with Android Studio

A series of flow of development environment construction using Android Studio

Here's a summary of what you've done to develop an Android app. The main goal is to create a mobile app development environment using Android Studio.

important point

Actually, the Qitta article was written as the update date, but I wrote this material about a year ago. So, think of this article as an article about December 2019. I want to put it on last year's calendar.

About deliverables and scope

Aiming to create an Android application development environment, do the following.

--Android Studio installation and settings --Emulator settings --Create Project and set build_gradle --Static resource placement --How to load the library --Introduction of libraries useful for testing

The actual application creation know-how is out of scope

Let's go

Install Android Studio

This is the official installation guide https://developer.android.com/studio/install?hl=ja

You can follow this instruction (it will also include emulator functions and speedup settings), but only one. When the installation is completed and the first startup Unable to access Android SDK add-on list Message may come. It is said that the SDK cannot be dropped on the network. In most cases, proxy cannot be passed, so putting this setting will solve it.

Follow the message guide or Once Android Studio has started, go to Configure> Setting> Appearance & Behavior> System Settings> HTTP Proxy and select Enter the proxy settings.

image.png

There is no need to write http in the Host name (only the host name is ok). After entering, press the check connection button and select the URL to use for the connection test (https://www.google.com/ etc.) If successfull, proxy setting is completed

Creating a project

You can create a project from Start a new Android Studio project

--Screen layout at startup ――Any --project name --package name --Directory location --Language (Java or Kotlin) --Select Java --minimum API level --Value of which Android version is supported (details will be described later in the build.gradle part). The new one will not be available to older Android versions --The approximate user ratio is displayed! So you should refer to it --No need for initial settings of instant apps --A function that allows you to use a native app just by following a link without installing the app. Instead, various work such as dividing modules into modules for each function of the application is required. --Details are out of scope, so they are omitted. For beginners like me, uncheck it.

About errors and warnings that are likely to occur when creating a project

Android Studio is configured to use a HTTP proxy. Gradle may need these HTTP proxy settings to access the Internet (e.g. for downloading dependencies.)  Would you like to copy the IDE's proxy configuration to the global gradle.properties file?  Note: To avoid potential security vulnerabilities, passwords will not be copied to the gradle.properties file. You can manually copy passwords to the gradle.properties file at your own risk.  For more details, please refer to the Android Studio documentation.

Whether to automatically generate proxy settings used by Gradle from Android Studio settings. Basic yes is fine, but the password is not written (to prevent direct writing), so you need to set it yourself

ERROR: Failed to install the following Android SDK packages as some licences have not been accepted.
   build-tools;28.0.3 Android SDK Build-Tools 28.0.3
   platforms;android-28 Android SDK Platform 28
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

The target SDK is not local (I have not agreed to use the license). Drop it from the SDK manager (Tool> SDK Manager)

Android Studio is using this JDK location:
/path/hoge/jre
which is different to what Gradle uses by default:
/path/huga/jre
Using different locations may spawn multiple Gradle daemons if
Gradle tasks are run from command line while using Android Studio.

Warning that the JDK used in Android Studio and the JDK (JAVA_HOME) used in the console are not the same Select JAVA_HOME (in the pull-down menu) for SDK Location> JDK Location from File> Project Structure on the toolbar. Android Studio will also use the JAVA_HOME JDK

Creating an emulator

You can create an emulator with Tools> AVD Manager on the toolbar.

At the bottom left, select the target device and system image from Create Visual Device to create an emulator. Should I choose the one with the Play Store? (Because it is subject to speedup)

Explain the structure of the created project

The structure of the project is as follows.

image.png

You can display the actual directory structure by changing Android on the Project tab bar to Project (upper left of the image). Of particular importance are the AndroidManifest.xml that resides in the two build.gradle and manifest.

build.gradle (directly under project root)

Describe the build settings for the entire project. Settings derived from the application (module) cannot be entered. In the early days of Android Studio, dependent repositories and default tasks (clean, etc.) are defined.

build.gradle (directly under module such as app)

Describe the build settings of the module (application). Define android sdk settings and app dependencies.

android sdk settings

When you create a project in Android Studio, most of the settings are automatically entered.

Library dependencies

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:2.28.2'

    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestUtil 'androidx.test:orchestrator:1.2.0'
}

The published one is specified by GroupID: ArtifactID: Version. You can change the dependency during testing, emulator testing, etc.

AndroidManifest.xml The Android build and Android OS determine the module information from this file. Details are below. https://developer.android.com/guide/topics/manifest/manifest-intro?hl=ja

The contents of the above link will be briefly explained below.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <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 android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.SEND_SMS"/>
    <uses-feature android:name="android.hardware.microphone" android:required="true" />

</manifest>

<application> Information about the application. Declare the application name (android: label), icon image (android: icon), activity of the screen to be used (<activity android: name =". MainActivity ">), etc. Static resources such as fixed character strings and images are stored in/app/res and can be referred to by a specific description.

<activity android:name=".MainActivity"/> Define the declaration of the activity (behavior of one screen) included in the application and the intent (like parameters) of the activity. Activities not declared here are not available to the application.

In the above example <category android:name="android.intent.category.LAUNCHER" /> It defines that it is the initial screen when it is started from the launcher with <action android:name="android.intent.action.MAIN" /> Defines that it can be the initial screen at startup regardless of the startup method (for example, even if it is started from another application).

<uses-permission> Permission for the function required by the app. If you do not have that authority, the operation will be restricted. You can operate it by voice, but you can also operate it on the screen, and you can limit the function depending on whether you have the authority of the microphone.

<uses-feature> Functions required for the app. If the function is not on the terminal, it cannot be installed.

Static resource configuration

image.png

Place static resources in the res directory. The following four are prepared by default.

Functionally, the above placement rule is not always absolute, but in general, it is placed according to such a rule.

Do you have two places to place images? ??

In the above, drawable and mipmap are both places to put images. There is a difference in the image size determination method between the two. Since each smartphone terminal has a different screen size, I want to change the size of the image or icon to be displayed according to the terminal. The recommended method is to prepare images of multiple sizes and display the appropriate type of image, but this selection method is different. drawable determines the image to display from the size of the terminal mipmap determines the image to be displayed from the actual drawing size that has undergone enlargement / reduction processing.

Since the launcher icon may be enlarged or reduced on the terminal side, put it in mipmap, and put it in drawable because you can decide the image to be displayed in the application by yourself.

However, mipmap can only be used with minSDK17 or later.

How to set the screen theme

You can set the theme (the appearance of the entire page) in value/style.xml as to what kind of screen layout to use.

Define the basic layout theme (which is provided) in parent You can adapt some to your liking by overwriting the items that the theme has. Details are out of scope, so I will omit them.

    <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>

Test library

Define test dependencies in app build.gradle

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

test ~~ is for local unit tests, it is executed by jvm and it does not depend on android. Mainly check DB and API calls. androidtest ~~ is an Instrumentation test that runs on a hard device or emulator and depends on Android. It will be a test including Android UI

At the same time, set testInstrumentationRunner

android{
    defaultConfig {
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
}

It means that the minimum test environment has been created.

Recommended library for testing

mockito By creating a mock class that returns the specified value, you can make a UnitTest that does not depend on other classes.

testImplementation 'org.mockito:mockito-cor:2.28.2'
Android{
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

Robolectrics You will be able to test UI etc. with test (on jvm) instead of android test. Define testImplementation'org.robolectric: robolectric: [VERSION]' and In addition, by making the ibrary that depends on android test such as androidx.test.ext: junit test-dependent in the same way, You will be able to test on jvm and emulation, all with the same source.

There may be many others, but this time it's all.

Summary

Isn't this ready for development for the time being? There are no mountains or valleys, but I hope it helps Android application development.

Recommended Posts

I tried to take a look at the flow of Android development environment construction with Android Studio
How to take a screenshot with the Android Studio emulator
I tried to create a padrino development environment with Docker
I tried to build a Firebase application development environment with Docker in 2020
I tried to implement a function equivalent to Felica Lite with HCE-F of Android
I tried to create a log reproduction script at the time of apt install
I tried to build the environment of WSL2 + Docker + VSCode
I tried to solve the problem of "multi-stage selection" with Ruby
I tried to create a simple map app in Android Studio
I tried to build an http2 development environment with Eclipse + Tomcat
I tried to create a Spring MVC development environment on Mac
I took a look at the resources of Azure Container Instance
I tried to check the operation of gRPC server with grpcurl
I tried to express the result of before and after of Date class with a number line
A record of setting up a Java development environment with Visual Studio Code
I tried to summarize the key points of gRPC design and development
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I tried migrating the portfolio created on Vagrant to the Docker development environment
I tried to measure and compare the speed of GraalVM with JMH
I tried to make a machine learning application with Dash (+ Docker) part1 ~ Environment construction and operation check ~
A reminder of Docker and development environment construction
I tried to break a block with java (1)
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
What I tried when I wanted to get all the fields of a bean
I tried to compare the infrastructure technology of engineers these days with cooking.
[Android] I tried to make a material list screen with ListView + Bottom Sheet
I tried to clone a web application full of bugs with Spring Boot
Let's take a look at the functions of Keycloak's management console (administrator edition)
I tried using a database connection in Android development
Environment construction method and troubleshooter at the time of joint development (rails, docker and github)
Introduction to Slay the Spire Mod Development (2) Development Environment Construction
I tried to check the operation of http request (Put) with Talented API Tester
I tried to summarize the state transition of docker
I saw the list view of Android development collectively
I tried to decorate the simple calendar a little
05. I tried to stub the source of Spring Boot
[Beginner's point of view] I tried to solve the FizzBuzz problem "easily" with Ruby!
I tried to reduce the capacity of Spring Boot
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
I tried to investigate the mechanism of Emscripten by using it with the Sudoku solver
Roughly the flow of web application development with Rails.
[Environment construction] Build a Java development environment with VS Code!
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
I tried to make a product price comparison tool of Amazon around the world with Java, Amazon Product Advertising API, Currency API (2017/01/29)
I tried using Docker because I don't want to pollute the local environment in Microsoft Teams tab development of MS Learn
Let's take a look at the functions of Keycloak's management console (user edition), user account service
I tried to make the sample application into a microservice according to the idea of the book "Microservice Architecture".
Since the reading of JdbcCodeList of TERASOLUNA is slow, I tried to register multiple at once.
I tried to develop the cache function of Application Container Cloud Service in the local environment
I want to recreate the contents of assets from scratch in the environment built with capistrano
I was addicted to WSl when trying to build an android application development environment with Vue.js
I tried to take a look at the flow of Android development environment construction with Android Studio
Docker × Java Building a development environment that is too simple
Java development environment (Mac, Eclipse)
A story that I finally understood Java for statement as a non-engineer
JSP + Eclipse + Jetty development environment construction that even Java beginners can do
A record of setting up a Java development environment with Visual Studio Code
[Processing x Java] Construction of development environment
Building a Lambda development environment in Eclipse
Let's create a Java development environment (updating)
Build a Java development environment on Mac
Introduction of IDOM engineer's development environment (physics)
Basics of Java development ~ How to write a program (flow and conditional branching) ~
I made a development environment with rails6 + docker + postgreSQL + Materialize.
I tried to modernize a Java EE application with OpenShift.
I took a peek at the contents of Java's HashMap
I tried to increase the processing speed with spiritual engineering
I tried to summarize the basics of kotlin and java
Let's take a look at the Hotspot JVM startup procedure
[Swift] I tried to implement the function of the vending machine
I tried JAX-RS and made a note of the procedure
I tried to summarize the basic grammar of Ruby briefly