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.
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.
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
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.
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
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.
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
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)
The structure of the project is as follows.
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.
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.
Describe the build settings of the module (application). Define android sdk settings and app dependencies.
When you create a project in Android Studio, most of the settings are automatically entered.
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.
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.
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.
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>
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.
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.
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