All Products
Document Center

Create a native project in Android Studio

Last Updated: Apr 06, 2021

This section introduces how to create a native project where a Toast pops up upon click on text, and obtain an APK installation package. The procedure falls into four steps:

  1. Create a project
  2. Compile code
  3. Create signature file and sign the project
  4. Install App on mobile phone

If you already have a native Android project which has been signed, you can skip this step, and directly Create an App in the mPaaS console.

Create a project

  1. Open Android Studio, and click File > New > New Project to create a project.
  2. In the pop-up window, select Empty Activity, and click Next.
    create new project

  3. Enter the Name, Package name (if any, you can use the default name), and Save location, with mPaaS mini program for example, and select API 21: Android 5.0 (Lollipop) as Minimum SDK.
    project name

  4. Click Finish to complete creating the project.

Compile code

  1. Open the file activity_main.xml underres/layout, and add a TextView with ID as “my_tv”.

    1. android:id="@+id/my_tv"
  2. Open the class MainActivity, and add the following code to set the click event on text.

    1. findViewById( View.OnClickListener() {
    2. @Override
    3. public void onClick(View v) {
    4. Toast.makeText(MainActivity.this, "Hello mPaaS!", Toast.LENGTH_SHORT).show();
    5. }
    6. });
  3. Compile and run the code. If the code runs successfully, it means you have completed the code compilation.

Create signature file and sign the project

  1. In the Android Studio, click Build > Generate Signed Bundle / APK.

  2. In the pop-up window, select APK, and click Next.

  3. Select Create new.
    create new

  4. Enter the corresponding information, and click OK. Then the signature is created. You can find the signature file in the Key store path you specified.
    new key store

  5. After filling the fields, click Next to sign the project.
    key store

  6. Select Build Variants on demand, and keep it in mind. When you use the encrypted file, the Build Variants must be consistent with that used in encrypted file generation.

    Check V1 (Jar Signature) as the signature version. The option V1 (Jar Signature) is required, while V2 (Full APK Signature) is optional.

  7. Click Finish. A moment later, you will find the signed APK installation package in the debug folder under ~\mPaaSminiprogram\app\debug. In this tutorial, the installation package is named “app-debug.apk”.
    apk created

Install App on mobile phone

  1. Connect your mobile to the computer, and turn on the USB debugging mode.
  2. Run the project in Android Studio to install the App on your mobile.
    app installed

  3. Open the App on the mobile, click the text Hello World!, and a Toast “Hello mPaaS!” appears. It means the App has been successfully installed and the expected function is realized.