All Products
Search
Document Center

Mobile Platform as a Service:Create a native project

Last Updated:Nov 01, 2023

In this topic, you will create an application on which a toast pops up when you click the text, and get a signed APK package. This process mainly includes the following four steps:

  1. Create a project

  2. Compile the project

  3. Create a signature file and sign the project

  4. Install the app on a mobile phone

If you already have a native Android project and the project has already been signed, redirect directly to Create an application in the mPaaS console.

Prerequisites

Before starting to create a project, make sure you have installed the mPaaS plug-in.

Create a project

  1. Start Android Studio, and click File > New > New Project.image.png

  2. In the Create New Project dialog box that appears, select Empty Activity, and click Next.image.png

  3. Set the project name (Name), package name (Package name), and storage path (Save location). These steps take the “mPaaS CDP” project as an example. Select API 18: Android 4.3 (Jelly Bean) as the Minimum SDK.image.png

  4. Click Finish to complete the project creation.

Compile the project

  1. Open the activity_main.xml file and refer to the following codes to add a button.

    <Button
         android:id="@+id/button"
         android:layout_width="101dp"
         android:layout_height="50dp"
         android:layout_marginStart="142dp"
         android:layout_marginTop="153dp"
         android:layout_marginBottom="151dp"
         android:text="Button"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
    image.png
  2. Open theMainActivity class and add a click event for the button.

             findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
                 @Override
                 public void onClick(View v) {
                     Toast.makeText(MainActivity.this, "Hello mPaaS!", Toast.LENGTH_SHORT).show();
                 }
             });
    image.png
  3. After a successful compilation, you have finished the code writing.

Create a signature file and sign the project

When configuring the component code in the mPaaS console, you need to use the signed APK file.

The steps to sign for the project and generate the APK file are as follows:

  1. In Android Studio, choose Build > Generate Signed Bundle / APK.image.png

  2. In the dialog box that appears, select APK, and click Next.image.png

  3. Select Create new.image.png

  4. Enter all the required information, and click OK to complete signature creation. You can obtain the generated signature file in the specified Key store path.image.png

  5. After the fields are automatically entered, click Next to start signing for the project.image.png

  6. Select Build Variants as needed, and check the encrypted version V1 (Jar Signature).

    Note that V1 (Jar Signature) is required while V2 (Full APK Signature) is optional.image.png

  7. Click Finish. After a while, in the debug folder (~\mPaaSCDP\app\debug) under the project folder, you can get the signed APK package of the project. In these steps, the name of the package is app-debug.apk.

Install the app on a mobile phone

  1. Connect a mobile phone to the computer and enable the USB Debugging mode of the mobile phone.

  2. In Android Studio, run the project to install the application on your phone.image.png

  3. Open the app and tap BUTTON. The toast “Hello mPaaS!” appears, as shown at the bottom of the screen. The display of this toast indicates that the app is installed and can function as expected. At this point, you have successfully installed the application on your phone.image.png