[Huawei Developers] Freemind R:
More articles like this, you can visit HUAWEI Developer Forum​

Downloading the AAR Packages and JSON File

o Sign in to HUAWEI Developer and download the AAR packages required.

o AAR packages related to HMS Push kit is displayed as below

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092324.25496755132568809784032474169667:50510706021834:2800:97CC018607E15931ADE40F7054D53015932415D1A696A8C2185DC7286451AE62.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092324.25496755132568809784032474169667:50510706021834:2800:97CC018607E15931ADE40F7054D53015932415D1A696A8C2185DC7286451AE62.png[/IMG]

Refer below link for the steps.

https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092611.75019895865492032901814085240237:50510706021834:2800:2162CE2A9645A75A8826541DD9C0BBAC273AB2F64E67418A621B73BB231E439C.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092611.75019895865492032901814085240237:50510706021834:2800:2162CE2A9645A75A8826541DD9C0BBAC273AB2F64E67418A621B73BB231E439C.png[/IMG]

Figure 1-2 Configuring app information in App Gallery Connect

Open AAR packages with rar tool and rename the class.jar and AndroidManifest.xml files. (It is recommended that the two files be renamed consistently with the AAR package names.)

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092705.60450961367338664117996704840081:50510706021834:2800:F25B157B8645498752AEFA955D1E5B6217C0899BF82B07F2BF41A6F1E585F735.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092705.60450961367338664117996704840081:50510706021834:2800:F25B157B8645498752AEFA955D1E5B6217C0899BF82B07F2BF41A6F1E585F735.png[/IMG]

Figure 1-3 Renaming files

Copy required permissions in the <manifest> section in B4A IDE

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092923.44120165137104404155049831219827:50510706021834:2800:4BC352779721BE6300641AF8C13C0D8AE67E95590D5669E3A45263A1A4F00FF7.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092923.44120165137104404155049831219827:50510706021834:2800:4BC352779721BE6300641AF8C13C0D8AE67E95590D5669E3A45263A1A4F00FF7.png[/IMG]

Figure 1-4 Permissions in the <manifest> section

Copy all configurations in the <application> section

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092956.67000636651110696993686127788210:50510706021834:2800:614A362E6A95B132B12800859375BD82A6B2F8267F66D4740F9ABF1E5CF1A975.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626092956.67000636651110696993686127788210:50510706021834:2800:614A362E6A95B132B12800859375BD82A6B2F8267F66D4740F9ABF1E5CF1A975.png[/IMG]

Figure 1-5 All configurations in the <application> section

Change ${applicationId} to $PACKAGE$.

${applicationId} is the field for automatically obtaining the package name in Android Studio. Its counterpart on B4A is $PACKAGE$

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626101204.36034247822294619738945186330551:50510706021834:2800:3BD64C34A81CFEBB215E2B482AC7361340E2F9EEC0BCE232B66062F87436415C.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626101204.36034247822294619738945186330551:50510706021834:2800:3BD64C34A81CFEBB215E2B482AC7361340E2F9EEC0BCE232B66062F87436415C.png[/IMG]

Download the latest configuration file(agconnect-services.json) from App Gallery Connect

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626093525.92079358661724143808709282178172:50510706021834:2800:B7A573766DF4547BBF511065DCF7BDED9751C657F8DD79D19F401531B206ED55.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626093525.92079358661724143808709282178172:50510706021834:2800:B7A573766DF4547BBF511065DCF7BDED9751C657F8DD79D19F401531B206ED55.png[/IMG]

Figure 1-6 Downloading the JSON file

Adding the JSON File to the assets Folder

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626093625.79301919610049415328389011454925:50510706021834:2800:E259075C8BBE5F5372E644BF8C65FE0ACA59D242EC7EFAB766B956210B287065.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626093625.79301919610049415328389011454925:50510706021834:2800:E259075C8BBE5F5372E644BF8C65FE0ACA59D242EC7EFAB766B956210B287065.png[/IMG]

Figure 1-7 Adding the JSON file

B4A will automatically incorporate files in the assets folder of an AAR package to the assets folder of your main project.

Encapsulating Java Files Using SLC

Configure the Java project.

SLC wraps Java project and adds it to the B4A library. For demonstration purposes, we have created a Java project.

It is recommended that you name the first folder b4x in src. Otherwise, the library generated with SLC may not function properly.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626093845.00974890138961480143725284714558:50510706021834:2800:5FAEA0E6F4C9C80F5365331902EDDD62E8378D9EC63CB22874CBD67185E0455F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626093845.00974890138961480143725284714558:50510706021834:2800:5FAEA0E6F4C9C80F5365331902EDDD62E8378D9EC63CB22874CBD67185E0455F.png[/IMG]

Figure 1-8 Java project

Develop the Java project.

Name the Java files based on the src path.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626093935.68200786581742476500615507067404:50510706021834:2800:27479107C9DBBA4B8AFC75A4EFB2F57E92AAAFB934F820B28D0341BDBF4D34ED.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626093935.68200786581742476500615507067404:50510706021834:2800:27479107C9DBBA4B8AFC75A4EFB2F57E92AAAFB934F820B28D0341BDBF4D34ED.png[/IMG]

Figure 1-9 Naming the files based on the src path

Import the following two lines of code to each Java file

import anywheresoftware.b4a.BA;

import anywheresoftware.b4a.BA.*;

Add necessary annotations to the Java files

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094109.60680657937920669962294136042955:50510706021834:2800:8B5F2BB0E4A84781FB4959D6084C8B4C24A557B20D2ABC2350087E4883F9E2AF.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094109.60680657937920669962294136042955:50510706021834:2800:8B5F2BB0E4A84781FB4959D6084C8B4C24A557B20D2ABC2350087E4883F9E2AF.png[/IMG]

Figure 1-10 Example annotations

Modify the context.

B4A does not recognize the Context class. Therefore, when parsing a class that contains the [MENTION=702169]version[/MENTION](1.0f) annotation, it will report an error if a method of the class has referenced Context. In this case, you need to change Context to the B4A object BA

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094152.58800780087558719864279699811160:50510706021834:2800:79A73F3E1C1BE5602EF15E723C141C6F5352AA0FF327F42C1F34059EB87C13FE.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094152.58800780087558719864279699811160:50510706021834:2800:79A73F3E1C1BE5602EF15E723C141C6F5352AA0FF327F42C1F34059EB87C13FE.png[/IMG]

Figure 1-11 Context example

The following describes the [MENTION=4297318]Events[/MENTION] annotation.

This annotation is used to report specific events in the Java method to the listener registered on B4A.

The code on B4A is also required to implement this function.

Take the getPushToken method in PushWork as an example. If you want to pass the push token in the Java method to a listener on B4A, do as follows:

Set a listening event on B4A.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094642.10953447258167950491713212507431:50510706021834:2800:13F298DF657EA3242DA4695CFF9B095D7C8A7D444EB33C595D85DA437C7679BE.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094642.10953447258167950491713212507431:50510706021834:2800:13F298DF657EA3242DA4695CFF9B095D7C8A7D444EB33C595D85DA437C7679BE.png[/IMG]

Figure 1-12 Setting a listening event

Add the [MENTION=961179]event[/MENTION] annotation to the Java files. The code is shown in the following figure.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094809.78449493387066781988207051179500:50510706021834:2800:12E2F48931B62A305D60311906B2E177668329BC9B20998092DBB6E5B1752D2B.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094809.78449493387066781988207051179500:50510706021834:2800:12E2F48931B62A305D60311906B2E177668329BC9B20998092DBB6E5B1752D2B.png[/IMG]

The value of NewToken in the red box must be the same as xxxx of Listener_xxxx in the listening event name added to B4A in the previous step.

Call the ba. raiseEventFromUI method in the method that needs to report the push token. The code is shown in the following figure.

Event reporting

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094922.50380537428549317145970214569199:50510706021834:2800:2414836D808970AEBC0B13C83BE367F7F73687B9ABA72621F3206E0FD994AC67.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626094922.50380537428549317145970214569199:50510706021834:2800:2414836D808970AEBC0B13C83BE367F7F73687B9ABA72621F3206E0FD994AC67.png[/IMG]

Select the project folder, define the library name, and click Compile

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200627113037.53393709189505922308561490000264:50510706021834:2800:937A10694444336B0F823BEF3625EADD15655048FD2E1F6C4E948118F27A2E30.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200627113037.53393709189505922308561490000264:50510706021834:2800:937A10694444336B0F823BEF3625EADD15655048FD2E1F6C4E948118F27A2E30.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200627113302.87146302528422889978017423200850:50510706021834:2800:4D58890D3C287D8DFC70B20825CF8A1412775574DCA5F2BBFA51A55B33B18E7A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200627113302.87146302528422889978017423200850:50510706021834:2800:4D58890D3C287D8DFC70B20825CF8A1412775574DCA5F2BBFA51A55B33B18E7A.png[/IMG]

Figure 1-14 Compilation successful

Select the Addition folder and add AAR packages to it.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626100139.24165728098916270584814544301209:50510706021834:2800:0B1FA742858E4FC5CF797413422F871F63CFA9BC40066B73819EFE5131F38C28.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626100139.24165728098916270584814544301209:50510706021834:2800:0B1FA742858E4FC5CF797413422F871F63CFA9BC40066B73819EFE5131F38C28.png[/IMG]

Figure 1-15 Tools-Configure Paths

Go to Project > Build Configurations and change the B4A project package name to the project package name configured in App Gallery Connect

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626100225.30600946669191674091686853404159:50510706021834:2800:393685AB7264B10045387DD4B6D7FAAEE86F7270B60512F4C1DBCF83EC7CB6CB.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626100225.30600946669191674091686853404159:50510706021834:2800:393685AB7264B10045387DD4B6D7FAAEE86F7270B60512F4C1DBCF83EC7CB6CB.png[/IMG]

Figure 1-16 Changing the B4A project package name

Go to Tools > Private Sign Key and select the SHA256 signature file specified in AppGallery Connect as the B4A project signature file

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626100316.99260787181324704400927442171122:50510706021834:2800:54C40AD0C2DFA3E61BFAE551F260DAA4067BB71F7DD3162DEF287650EA46A078.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/116/0890091000000002116.20200626100316.99260787181324704400927442171122:50510706021834:2800:54C40AD0C2DFA3E61BFAE551F260DAA4067BB71F7DD3162DEF287650EA46A078.png[/IMG]

Figure 1-17 Configuring the signature file

Declare MainApplication in the Manifest file.

The path of MainApplication must also be the path to the src folder where MainApplication is located.

Add the #AdditionalJar field to Project Attributes to reference the AAR packages

The value of #AdditionalJar is the name of the AAR package (with a file name extension) in the Addition folder