Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Google License Verification - Need help.

Discussion in 'Android' started by DanRP, Aug 27, 2013.

  1. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    Hello Everyone,

    I'm working on adding Google Play license verification to my app and am having an issue I can't resolve. I am able to run the LVL_Example (CheckLVLButton) that came with the add-on. When I run the example code, the call works and returns the correct return code.

    Now I am trying to integrate this code to my app and am running into a problem with this code:

    Code (csharp):
    1. public TextAsset ServiceBinder;
    2.  
    3. private void LoadServiceBinder() {
    4.     byte[] classes_jar = ServiceBinder.bytes;
    5.  
    6.     m_Activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
    7.     m_PackageName = m_Activity.Call<string>("getPackageName");
    8.  
    9.     string cachePath = System.IO.Path.Combine(m_Activity.Call<AndroidJavaObject>("getCacheDir").Call<string>("getPath"), m_PackageName);
    10.     System.IO.Directory.CreateDirectory(cachePath);
    11.  
    12.     System.IO.File.WriteAllBytes(cachePath + "/classes.jar", classes_jar);
    13.     System.IO.Directory.CreateDirectory(cachePath + "/odex");
    14.  
    15.     AndroidJavaObject dcl = new AndroidJavaObject("dalvik.system.DexClassLoader",
    16.                                                       cachePath + "/classes.jar",
    17.                                                       cachePath + "/odex",
    18.                                                       null,
    19.                                                       m_Activity.Call<AndroidJavaObject>("getClassLoader"));
    20.     m_LVLCheckType = dcl.Call<AndroidJavaObject>("findClass", "com.unity3d.plugin.lvl.ServiceBinder");
    21.  
    22.     System.IO.Directory.Delete(cachePath, true);
    23. }
    When the following line of code gets executed:
    Code (csharp):
    1. m_Activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
    ... I get a run-time error of "Exception: JNI: Init'd AndroidJavaClass with null ptr!".

    This exact same code runs fine in the example code, but fails when I use it in my own code.



    Thanks!
    Dan
     
    Last edited: Aug 27, 2013
  2. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    I think I was getting this error because I was running in the editor. It seems to work fine on an android device...
     
  3. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    Yes, the JNI will not run in the Unity editor.. so you will always get an exception when anything tries to do so.
     
  4. Viltro

    Viltro

    Joined:
    Oct 11, 2013
    Posts:
    3
    I too am having trouble getting this to work. I am running it on an android device (nook HD), I managed to get the debugger to attach to the process running on the device but when I get to the line "m_LVLCheckType = dcl>Call<AndroidJavaObject>("findClass", "com.unity3d.plugin.lvl.ServiceBinder");" and try to step over it, the app hangs. I am getting no errors in the output window. I assumed in the properties of the game object where I attached the C# code I am supposed to assign "AndroidManifest" to the variable "Service Binder". Without assigning "AndroidManifest" the app crashes. Is that the right thing to assign to this variable? I wish there were a little more documentation on how to incorporate this into an app, seems like I am just stabbing in the dark.
     
    jimrota likes this.
  5. Spierek

    Spierek

    Joined:
    Mar 4, 2013
    Posts:
    11
    There seems to be a similar issue in current builds (from Unity 2019.1 to the latest version, 2019.2.17f1) that hasn't been resolved at least since May 2019 - https://github.com/Unity-Technologies/GooglePlayLicenseVerification/issues/9

    Calling this line: m_LVLCheckType = dcl>Call<AndroidJavaObject>("findClass", "com.unity3d.plugin.lvl.ServiceBinder"); seems to throw the following exception, and as a result, the license cannot be properly verified:

    AndroidPlayer(samsung_SM-G903F@192.168.1.7) AndroidJavaException: java.lang.ClassNotFoundException: Didn't find class "com.unity3d.plugin.lvl.ServiceBinder" on path: DexPathList[[zip file "/data/user/0/com.Afterburn.GolfPeaks/cache/com.Afterburn.GolfPeaks/classes.jar"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    java.lang.ClassNotFoundException: Didn't find class "com.unity3d.plugin.lvl.ServiceBinder" on path: DexPathList[[zip file "/data/user/0/com.Afterburn.GolfPeaks/cache/com.Afterburn.GolfPeaks/classes.jar"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    at com.unity3d.player.UnityPlayer.c(Unknown Source)
    at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:158)
    at com.unity3d.player.UnityPlayer$e.run(Unknown Source)
    Suppressed: java.io.IOException: No original dex files found for dex location (arm) /data/user/0/com.Afterburn.GolfPeaks/cache/com.Afterburn.GolfPeaks/classes.jar (/data/user/0/com.Afterburn.GolfPeaks/cache/com.Afterburn.GolfPeaks/odex/classes.dex)
    at dalvik.system.DexFile.openDexFileNative(Native Method)
    at dalvik.system.DexFile.openDexFile(DexFile.java:295)
    at dalvik.system.DexFile.<init>(DexFile.java:111)
    at dalvik.system.DexFile.loadDex(DexFile.java:151)
    at dalvik.system.DexPathList.loadDexFile(DexPathList.java:282)
    at dalvik.system.DexPathList.makePathElements(DexPathList.java:248)
    at dalvik.system.DexPathList.<init>(DexPathList.java:120)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
    at dalvik.system.DexClassLoader.<init>(DexClassLoader.java:57)
    ... 6 more
    at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.AndroidJNISafe.CallObjectMethod (System.IntPtr obj, System.IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.AndroidJavaObject._Call[ReturnType] (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.AndroidJavaObject.Call[ReturnType] (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0
    at CheckLVLButton.LoadServiceBinder () [0x00000] in <00000000000000000000000000000000>:0
    at CheckLVLButton.Start () [0x00000] in <00000000000000000000000000000000>:0

    (Filename: currently not available on il2cpp Line: -1)

    According to this post the issue has been successfully reproduced back in September but it doesn't look like there has been any progress. cc @Yury-Habets
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are you able to reproduce?
     
  7. Spierek

    Spierek

    Joined:
    Mar 4, 2013
    Posts:
    11
    Since my previous post we managed to figure out a solution together with some other developers in the Github issue I linked previously - https://github.com/Unity-Technologies/GooglePlayLicenseVerification/issues/9 (for anyone wrestling with the problem, please refer to that link for more info)

    This behaviour should be easily reproducible using steps outlined by user MigrantP:

    Download the project from https://github.com/Unity-Technologies/GooglePlayLicenseVerification and open in Unity 2019.1.10f1.
    Add the RSA key info needed in CheckLVLButton.cs.
    Set the Android package name.
    Set Install Location to Automatic.
    Build and run to a device.
    adb logcat will show the exception.

    You can also wrap the code in LoadServiceBinder() with a try/catch and look at the exception in more detail.

    The issue seems to stem from the fact that the provided example uses a dexed version of the plugin - switching it out for the regular ServiceBinder.java plugin and replacing relevant code with simpler calls (below) should eliminate errors.

    Code (CSharp):
    1. m_LVLCheck = new AndroidJavaObject("com.unity3d.plugin.lvl.ServiceBinder", m_Activity);
    The rest seems to be making sure that the resulting AndroidManifest.xml file contains a CHECK_LICENSE permission, that relevant tester e-mail addresses have been inputted into the Google Play Console, and that the build with said permission has been uploaded to any of the release tracks (even Internal) at least once.
     
    kmedved likes this.