All Products
Search
Document Center

Create App in Android Studio

Last Updated: Feb 20, 2021

In this section, you will create an app that causes a Toast to appear when a user clicks a button, and obtain the installation package in APK format.

This process mainly includes the following four steps:

  1. Create a project
  2. Write the code
  3. Create a signature file and add the signature to the project
  4. Install the app on a cell phone

If you already have a native Android development project and it is already signed, you may skip this tutorial and directly Create an app on the mPaaS console.

Create a project

  1. Start Android Studio and choose File > New > New Project.
    Open
  2. In the Create New Project dialog box that appears, select Empty Activity and click Next.
    Select
  3. Enter the Name, Package name (the default value may be used), and Save location. Enter H5 Application as the Name here. Select API 18: Android 4.3 (Jelly Bean) as the Minimum SDK.
    Note: “API 18: Android 4.3 (Jelly Bean)” is the earliest version supported by mPaaS. You can select a version based on your needs in the actual production environment.
    1
  4. Click Finish to complete creation of the project.

Write the code

  1. Open the file activity_main.xml and add a button by referring to the following code.
       
    1. <Button
    2. android:id="@+id/button"
    3. android:layout_width="101dp"
    4. android:layout_height="50dp"
    5. android:layout_marginStart="142dp"
    6. android:layout_marginTop="153dp"
    7. android:layout_marginBottom="151dp"
    8. android:text="Button"
    9. app:layout_constraintStart_toStartOf="parent"
    10. app:layout_constraintTop_toTopOf="parent" />
    2
  2. Open the class MainActivity and add the click event for the button.
       
    1. findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
    2. @Override
    3. public void onClick(View v) {
    4. Toast.makeText(MainActivity.this, "Hello mPaaS!", Toast.LENGTH_SHORT).show();
    5. }
    6. });
    3
  3. After the compilation succeeds, you will have completed writing the code.

Create a signature file and add the signature to the project

  1. In Android Studio, choose Build > Generate Signed Bundle / APK.
    3-1
  2. In the dialog box that appears, select APK and click Next.
    Select APK
  3. Click Create new.
    Create key
  4. After entering all the required information, click OK and you will complete creating the signature. You can obtain the generated signature file in the specified Key store path.
    4
  5. After the contents are automatically entered, click Next to start adding the signature to the project.
    5
  6. Based on your needs, select Build Variants and then V1 (Jar Signature) as the signature version. Note that V1 (Jar Signature) is required while V2 (Full APK Signature) is optional.
    6
  7. Click Finish. After the packaging is complete, you will find the signed APK installation package for this app in the debug folder of the project directory (~\MyHApplication\app\debug). In this tutorial, the name of the installation package is app-debug.apk.
    APK

Install the app on a cell phone

  1. Connect a cell phone to the computer and enable the USB Debugging mode of the cell phone.
  2. Run the project.
    Run
  3. Click BUTTON. If you see the Toast shown in the following figure, then it means the app was successfully installed and the expected function was implemented. Now, you have completed installing the app on a cell phone.
    7