We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesGame ServiceAppendixIntegrating the HMS Core SDK into Your App Project in the Eclipse IDE

Integrating the HMS Core SDK into Your App Project in the Eclipse IDE

If you are using Eclipse, you can download the HMS Core SDK and integrate it into your Eclipse project.

Downloading the SDK

  1. Download and decompress the ZIP packages of the HMS Base SDK and SDKs of the required kits.

    For details, please refer to Game Service SDK Download.

  2. Import all SDK projects to your workspace.

    1. Go to File > Import > Android > Existing Android Code Into Workspace and click Next.

    2. Click Browse and navigate to the directory where your projects are located. Select the desired projects under Projects and click Finish. By default, all projects are selected, and you can change as needed.
      NOTE

      The projects to be imported must be located in the same drive as your workspace, for example, D:\. If they are not in the same drive, select Copy projects into workspace to copy the projects to the workspace.

Adding Project Dependencies

  1. Right-click your app project and choose Properties from the shortcut menu.
  2. Choose Android from the navigation tree. Then, click Add in the Library area, select the imported projects, and click Apply and Close.

  3. Right-click the HMSSdkAvailableUpdate project and choose Properties from the shortcut menu.
  4. Choose Android from the navigation tree. Then, click Add in the Library area, select the HMSSdkUI project, and click Apply and Close.

  5. Because the XML file in the Eclipse IDE does not support the dollar sign ($), replace ${applicationId} in the AndroidManifest.xml file of the Agconnect-core, HMSSdkAvaliableUpdate, HMSSdkDevice, and Update projects with your app package name.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. <application>
    2. <provider
    3. android:name="com.huawei.agconnect.core.provider.AGConnectInitializeProvider"
    4. android:authorities="${applicationId}.AGCInitializeProvider"
    5. android:exported="false" />
    6. <service
    7. android:name="com.huawei.agconnect.core.ServiceDiscovery"
    8. android:exported="false" />
    9. </application>

Copying the HMSSdkStats Resource Files to Your Project Directory

Copy the resource files in the assets directory of the HMSSdkStats project to the assets directory of your project.

NOTE

If any other kits are involved, also copy their resource files to your project directory.

Configuring the project.properties File

Open the project.properties file in your project directory, and add the following code to merge the Manifest files in the subprojects:

Collapse
Word wrap
Dark theme
Copy code
  1. manifestmerger.enabled=true
NOTE

The ADT version must be 17 or later.

Adding the AppGallery Connect Configuration File of Your App

  1. Sign in to AppGallery Connect and click My projects.
  2. Find your app project and click the app that needs to integrate the HMS Core SDK.
  3. Go to Project settings > General information. In the App information area, download the agconnect-services.json file.
  4. Because the Eclipse IDE does not support the AppGallery Connect plugin, place the agconnect-services.json file in the assets directory of your project and add the following code to the Application subclass of the project. If the project does not have an Application subclass, create a subclass that extends the Application subclass, for example, MyApplication.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. // TODO: Import the following classes:
    2. import java.io.IOException;
    3. import java.io.InputStream;
    4. import com.huawei.agconnect.config.AGConnectServicesConfig;
    5. import com.huawei.agconnect.config.LazyInputStream;
    6. import android.app.Application;
    7. import android.content.Context;
    8. import android.util.Log;
    9. public class MyApplication extends Application{
    10. @Override
    11. public void onCreate() {
    12. super.onCreate();
    13. }
    14. // TODO: Add the following code:
    15. @Override
    16. protected void attachBaseContext(Context context) {
    17. super.attachBaseContext(context);
    18. AGConnectServicesConfig config = AGConnectServicesConfig.fromContext(context);
    19. config.overlayWith(new LazyInputStream(context) {
    20. public InputStream get(Context context) {
    21. try {
    22. return context.getAssets().open("agconnect-services.json");
    23. } catch (IOException e) {
    24. return null;
    25. }
    26. }
    27. });
    28. }
    29. // TODO: End
    30. }

  5. Open the AndroidManifest.xml file of your project and add the Application subclass name to the application element. If the subclass name has been added, skip this step. For example, add the MyApplication class name.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. <application
    2. android:name=".MyApplication"
    3. ...
    4. >
    5. ...

  6. In the Eclipse IDE menu bar, click Project, and then Clean.

Configuring Obfuscation Scripts

Before building the APK, configure the obfuscation configuration file to prevent the HMS Core SDK from being obfuscated.

Open the obfuscation configuration file proguard-project.txt and add configurations to exclude the HMS Core SDK from obfuscation.
Collapse
Word wrap
Dark theme
Copy code
  1. -ignorewarnings
  2. -keepattributes *Annotation*
  3. -keepattributes Exceptions
  4. -keepattributes InnerClasses
  5. -keepattributes Signature
  6. -keepattributes SourceFile,LineNumberTable
  7. -keep class com.huawei.hianalytics.**{*;}
  8. -keep class com.huawei.updatesdk.**{*;}
  9. -keep class com.huawei.hms.**{*;}
Search in Guides
Enter a keyword.