Search Unity

Does anybody know how to apply this plugin?

Discussion in 'Editor & General Support' started by blablaalb, Jun 15, 2020.

  1. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    I want to be able to determine whether my game is running on android emulator or on a real device. In searching for answers I stumbled across this plugin. I tried to integrate it into my project, but haven't succeeded so far.
    What I did:
    • Made a file named mainTemplate.gradle at the following location: Assets\Plugins\Android\mainTemplate.gradle and with the following content:
      Code (CSharp):
      1. allprojects {
      2. repositories {
      3.     jcenter()
      4.     maven { url "https://jitpack.io" }
      5. }
      6. }
      7.  
      8. dependencies {
      9.     compile 'com.github.mofneko:EmulatorDetector:1.1.0'
      10. }
      11.  
      12. EmulatorDetector.isEmulator(this);
    • Copied the library-release.aar file into the Assets\Plugins\Android\ folder.
    • Copied this snipped to the Start method:
      Code (CSharp):
      1.             AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
      2.             AndroidJavaObject context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity").Call<AndroidJavaObject>("getApplicationContext");
      3.             AndroidJavaClass cls = new AndroidJavaClass("com.nekolaboratory.EmulatorDetector");
      4.             _result = cls.CallStatic<bool>("isEmulator", context);
    When I try to run the project inside the editor I get the following error:
    And if I try to build the project I get a bunch of errors:
     

    Attached Files:

  2. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    I managed to get rid of these errors by renaming the mainTemplate.gradle to build.gradle, but the plugin doesn't work. I ran the app on the Nox Emulator and unfortunately the plugin failed to detect that.