In this section, you will create a native project that displays a Toast message when you tap the text and obtain an installation package in APK format.
The procedure to create the native project includes the following four steps:
If you already have a signed native Android development project, skip to Create an application in the mPaaS console.
Create a project
Open Android Studio and click File > New > New Project.
In the new project window, select Empty Activity and click Next.
Enter a Name, Package name (use the default value if you do not have one), and Save location. In this example, set Name to mPaaS mini program. Set Minimum SDK to API 21: Android 5.0 (Lollipop).
Click Finish to create the project.
Write the code
Open the
activity_main.xmlfile underres/layout. Add the following code to create a TextView with the ID "my_tv".android:id="@+id/my_tv"Open the
MainActivityclass. Add the following code to set the click event for the text.findViewById(R.id.my_tv).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "Hello mPaaS!", Toast.LENGTH_SHORT).show(); } });Compile and run the code. A successful run completes the procedure.
Create a signature file and sign the project
In Android Studio, click Build > Generate Signed Bundle / APK.
In the window that appears, select APK and click Next.
Click Create new.
Fill in the required information and click OK to create the signature. The generated signature file is located at the specified Key store path.
After the fields are automatically populated, click Next to start signing the project.
Select a Build Variants value as needed. Remember the selected value because you must use the same value when you use the encrypted file. Select the V1 (Jar Signature) checkbox. This option is required. The V2 (Full APK Signature) option is optional.
Click Finish. After a moment, the signed APK installation package is generated in the
debugfolder (~\mPaaSminiprogram\app\debug) under your project folder. In this tutorial, the package is namedapp-debug.apk.
Install the application on a mobile phone
Connect a mobile phone to the computer and enable USB debugging mode on the phone.
Run the project in Android Studio to install the application on the phone.
Open the application on the phone and tap the Hello World! text. A Toast message "Hello mPaaS!" appears at the bottom of the screen. This confirms that the application is installed correctly and functions as expected.