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:
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
Open Android Studio, and click File > New > New Project to create a project.
In the pop-up window, select Empty Activity, and click Next.
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.
Click Finish to complete creating the project.
Compile code
Open the file
activity_main.xmlunderres/layout, and add a TextView with ID as “my_tv”.android:id="@+id/my_tv"Open the class
MainActivity, and add the following code to set the click event on 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. If the code runs successfully, it means you have completed the code compilation.
Create signature file and sign the project
In the Android Studio, click Build > Generate Signed Bundle / APK.
In the pop-up window, select APK, and click Next.
Select Create new.
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.
After filling the fields, click Next to sign the project.
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.
Click Finish. A moment later, you will find the signed APK installation package in the
debugfolder under~\mPaaSminiprogram\app\debug. In this tutorial, the installation package is named “app-debug.apk”.
Install App on mobile phone
Connect your mobile to the computer, and turn on the USB debugging mode.
Run the project in Android Studio to install the App on your mobile.
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.