Unity-Technologies / HuaweiServiceSample

Public repository for HUAWEI HMS & AGC Unity SDK
43 stars 19 forks source link

java.lang.NoSuchMethodError: No static method checkAppUpdateByAppInfo #11

Closed Filfur closed 3 years ago

Filfur commented 3 years ago

Hello! We use HMS plugin (https://assetstore.unity.com/packages/add-ons/services/huawei-hms-agc-services-176968) (version 1.2) to add Huawei ads to our application.

Now we are unable to upload the application to the AppGallery due to the fact that after running the application via UDP, it crashes at startup with the following error:

Caused by java.lang.NoSuchMethodError: No static method checkAppUpdateByAppInfo(Landroid/content/Context;Lcom/huawei/updatesdk/service/otaupdate/CheckUpdateCallBack;Lcom/huawei/updatesdk/service/appmgr/bean/AppInfoAdapter;)V in class Lcom/huawei/updatesdk/UpdateSdkAPI; or its super classes (declaration of 'com.huawei.updatesdk.UpdateSdkAPI' appears in /data/app/brick.breaker.huawei-1/base.apk:classes3.dex) at com.huawei.hms.jos.AppUpdateClientImpl$b.a() at com.huawei.hms.jos.AppUpdateClientImpl$b.onSuccess() at com.huawei.hmf.tasks.a.h$1.run() at android.os.Handler.handleCallback(Handler.java:754) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:163) at android.app.ActivityThread.main(ActivityThread.java:6238) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

The APK file before running over UDP works correctly and this error does not occur, but this error occurs in the APK returned to us by UDP.

I tried to decompile the resulting APK file (from UDP) and in classes3.dex I found the classes indicated in the error and all the methods are there. ProGuard and obfuscation are disabled for us.

Earlier (about a month ago) we were able to successfully build everything and put it in the AppGallery, since then we have not changed or updated the plugin. We also tried to build older versions of our application and run it over UDP, but we got the same error.

It was also found that this error occurs exactly when the HMS Core application has not been updated on the device (the method specified in the error is apparently called in this case).

Therefore, this suggests that this could be a bug in APK build in UDP side, so I duplicated this issue in github (https://github.com/Unity-Technologies/HuaweiServiceSample/issues/new) and submit a request to unity support ( https://support.unity.com/hc/en-us/requests/).

I hope you can help and clarify what's going on.

SiyaoHuang commented 3 years ago

Hi @Filfur, This is possibly because the version of hms package is conflicted with each other. udp uses new version of hms sdk now.

Could you share your package configuration, like gradle?

Filfur commented 3 years ago

baseProjectTemplate.gradle

...
buildscript {
    repositories {**ARTIFACTORYREPOSITORY**
        google()
        jcenter()
        maven { url 'https://developer.huawei.com/repo/' }
    }
    dependencies {
        // If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
        // See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html
        // See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
        // To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'com.huawei.agconnect:agcp:1.2.1.301'
        **BUILD_SCRIPT_DEPS**
    }
}
...

launcherTemplate.gradle

...
dependencies {
    implementation project(':unityLibrary')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
    implementation 'com.huawei.hms:ads-lite:13.4.29.303'
    implementation 'com.huawei.hms:hwid:4.0.1.300'
    implementation 'com.huawei.hms:base:4.0.1.300'
}
...

mainTemplate.gradle

...
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
    implementation 'com.huawei.hms:base:4.0.1.300'
    implementation 'com.huawei.hms:hwid:4.0.1.300'
    ...
}
...
Filfur commented 3 years ago

I also noticed that this error only occurs when building a release build. When building a debug build, after running apk through UDP, everything works fine.

Filfur commented 3 years ago

I also tried updating the version of the HMS plugin, but I still got this error

CoffeyMiao commented 3 years ago

Hi @Filfur , the following are the HMS dependency libraries we use now:

implementation 'com.huawei.hms:base:5.0.5.300'
implementation 'com.huawei.hms:hwid:5.0.5.301'
implementation 'com.huawei.hms:iap:5.0.4.301'
implementation 'com.huawei.hms:game:5.0.4.302'
implementation 'com.huawei.agconnect:agconnect-core:1.4.2.300'

Regarding the issue of release build, it may be caused by confusion. Please refer to the document to configure your project.

Filfur commented 3 years ago

I have updated hms unity plugin to latest version and specified the required dependencies. Thanks a lot, it works now! But, please, update documentation according to your answer.

Also I want to tell about some problem that I should have fixed, when I install latest version of plugin:

Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included or the current platform. Only one assembly with the same name is allowed per platform. Assembly paths: "project path"/Library/PackageCache/com.unity.nuget.newtonsoft-json@2.0.0/Runtime/Newtonsoft.Json.dll Assets/HuaweiService/cloud_function/Newtonsoft.Json.dll So I have removed yours and left imported by UPM.