3

I have converted the code with the help of HMS toolkit to support both GMS and HMS. but after the conversion, it crashes and throws exception.

Process: com.example.android.wander.huawei, PID: 10649 java.lang.VerifyError: Verifier rejected class com.example.android.wander.huawei.MapsActivity: void com.example.android.wander.huawei.MapsActivity.onCreate(android.os.Bundle) failed to verify: void com.example.android.wander.huawei.MapsActivity.onCreate(android.os.Bundle): [0x11] 'this' argument 'Reference: androidx.fragment.app.FragmentManager' not instance of 'Reference: androidx.fragment.app.FragmentManager' (declaration of 'com.example.android.wander.huawei.MapsActivity' appears in /data/app/~~M8blTtc1ehsAE-ySiPYUtQ==/com.example.android.wander.huawei-0H3LEYclNRMAw9Pq-MrWww==/base.apk) at java.lang.Class.newInstance(Native Method) at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95) at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45) at android.app.Instrumentation.newActivity(Instrumentation.java:1253) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

after i removed the line from application class.

XLoader.init(this);

this exception went away and then

SupportMapFragment.newInstance()

throws runtimeexception 'stub'

Taha alam
  • 372
  • 3
  • 11

1 Answers1

0

Please refer to Map Kit Manual Conversion Guide and follow the guide step by step. After the Add HMS API conversion is complete, you can configure the ClassLoader (simple, only resource import and configuration file modification are required) or manually write code (complex, heavy manual conversion workload) to implement the compatibility of Google APIs and HMS for activity displayed in fragment.

Currently, the ClassLoader solution does not support the plug-in or hot fix framework in projects, and does not support ClassLoader customization. If your app has such requirements, manually write the code.


When the Add HMS API policy is used, the XClassLoader solution is provided to solve the problem that some APIs cannot be converted in combination mode. This solution is used to reduce the workload of manually modifying resources. In this mode, the tool generates a built-in xmsaux module in the xmsadapter module. The xmsaux module contains the xg, xh, and xapi modules and the XClassLoader code.

  1. Modify the project-related configuration files.

a. If Generate code for creating app dependent only on GMS SDK is selected and the single xmsg flavor variant is enabled, modify the reference configuration in the project-level settings.gradle file as follows:

include ':xmsadapter:xmsaux', 'xmsadapter:xmsaux:xg', 'xmsadapter:xmsaux:xapi'

If Generate code for creating app dependent only on HMS SDK is selected and the single xmsh flavor variant is enabled, modify the reference configuration in the project-level settings.gradle file as follows:

include ':xmsadapter:xmsaux', 'xmsadapter:xmsaux:xh', 'xmsadapter:xmsaux:xapi'

If any of the preceding modes is selected and the single xmsgh flavor variant is enabled, modify the reference configuration in the project-level settings.gradle file as follows:

include ':xmsadapter:xmsaux', 'xmsadapter:xmsaux:xg', 'xmsadapter:xmsaux:xh', 'xmsadapter:xmsaux:xapi'

b. In the dependencies {} section of the project-level build.gradle file, set the Gradle plug-in version to 3.5.0 or later.

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

c. In the project-level gradle/wrapper/gradle-wrapper.properties file, set the Gradle version to 5.4.1 or later.

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

d. For a multi-module project, add the following configuration to the gradle.properties file in the project-level directory:

android.enableD8=false
android.enableD8.desugaring=false
  1. Call the init method at the program entry to initialize the program. a. Implement a program entry class that inherits android.app.Application in the app and override the onCreate method in the class.
public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        GlobalEnvSetting.init(this,null);
        XLoader.init(this);
    }
}

b. Modify the application name attribute in the app-level src/main/AndroidManifest.xml file and add the new application subclass in the first entry.

<application
    android:name=".MyApp"
</application>
  1. Handle the exception.

  1. Modify the layout resource files. In the Add HMS API scenario, Google APIs and HMS need to use independent layout resource files. The class paths in the resource files are different. Each layout resource file must be in duplicate, one for HMS and the other for Google APIs. The files are used together with the code for compatible redirection.

  2. Modify the code. If Fragment is used, you can use if-else in the onCreate() method of activity to make a copy of the code compatible with both HMS and Google APIs.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108