Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Huawei DRM plugin ?

Discussion in 'Android' started by starmindfr, Nov 16, 2020.

  1. starmindfr

    starmindfr

    Joined:
    Nov 7, 2016
    Posts:
    38
    Hello i am using by now a project in unity 2019 and publishing on HUAWEI store (appgalery)

    Issue is that Huawei for full support ask to integrate the DRM KIT that is only avalaible in android studio and not in c#

    did anyone suceed to include the huawei-android-drm_v2.5.2.300.jar with JNI or to call the licencing data with url API ?

    I tried to export all to android studio in order to add the .jar but it's time consuming and i am loosing Unity use if i need to do that for each release.

    I checked in Both the current HMS plugin from Unity and the one for EvilMindDevs and they dont include the DRM part.

    i gave a try to ikvm but obviously the .jar need all the kits with deep links

    Thanks for any help.
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    If you have a .jar file that has to be used in a project, you should be able to use it as a plugin in Unity project. Take a look at this page https://docs.unity3d.com/2019.4/Documentation/Manual/AndroidJARPlugins.html
     
  3. starmindfr

    starmindfr

    Joined:
    Nov 7, 2016
    Posts:
    38
    thanks JuliusM but i am lost with the samples

    I need to call :
    Drm.check(this,this.getPackageName(), DRM_ID,DRM_PUBLIC_KEY,new HWDrmCheckCallback() );

    How could i implement the Callback that extends DrmCheckCallback ?

    import com.huawei.android.sdk.drm.Drm; << first step
    import com.huawei.android.sdk.drm.DrmCheckCallback; << callback

    full code to convert
    Code (CSharp):
    1.    private static final String DRM_ID ="xxx";
    2.    private static final String DRM_PUBLIC_KEY="xxx";
    3.  
    4.    @Override
    5.    protected void onCreate(Bundle savedInstanceState) {
    6.       super.onCreate(savedInstanceState);
    7.  
    8.       Drm.check(this,this.getPackageName(), DRM_ID,DRM_PUBLIC_KEY,new HWDrmCheckCallback() );
    9.    }
    10.  
    11.  
    12.    private class HWDrmCheckCallback implements DrmCheckCallback{
    13.  
    14.       @Override
    15.       public void onCheckSuccess(){
    16.          //setContentView(R.layout.activity_main);
    17.       }
    18.  
    19.       @Override
    20.       public void onCheckFailed(){
    21.          finish();
    22.       }
    23.    }
    i tried following but each time i get a method not found error in android

    Code (CSharp):
    1.         AndroidJNIHelper.debug = true;
    2.         try
    3.         {
    4.             using (AndroidJavaClass drm2 = new AndroidJavaClass("com.huawei.android.sdk.drm.Drm"))
    5.             {
    6.                 drm2.CallStatic("check", "this", "this.getPackageName()", DRM_ID, DRM_PUBLIC_KEY, "new HWDrmCheckCallback()");
    7.             }
    8.         } catch (Exception e)
    9.         {
    10.             Debug.Log("[HMSPlugin]: error 1:"+e.Message);
    11.         }
    12.         try
    13.         {
    14.             using (AndroidJavaClass drm2 = new AndroidJavaClass("com.huawei.android.sdk.drm.Drm"))
    15.             {
    16.                 drm2.CallStatic("Drm.check", "this", "this.getPackageName()", DRM_ID, DRM_PUBLIC_KEY, "new HWDrmCheckCallback()");
    17.             }
    18.         }
    19.         catch (Exception e)
    20.         {
    21.             Debug.Log("[HMSPlugin]: error 2:" + e.Message);
    22.         }
    and i moved file huawei-android-drm_v2.5.2.300.jar in my andoid plugins folder
     
    Last edited: Nov 17, 2020
  4. starmindfr

    starmindfr

    Joined:
    Nov 7, 2016
    Posts:
    38
    I made it in another way (not the best but at least i stop wasting time) :

    - create an empty android studio project
    - move the DRM KIT .jar + unity classes.jar
    - in the main activity code of android studio i pasted the code to call DRM.check and pass the 2 arguments
    - build done as .aar
    - removed the classes.jar from new packages
    - droped it inside android plugins libs.

    So like this the extra code from the new android package will call the official DRM kit sending the DRM ID values and running few logs entries added for debug.

    only needed to tweak a little the android manifest to avoid issues with ressources and that's all.
     
    Last edited: Nov 18, 2020