0

I use the android-beacon-library-2.17.1.aar to make an Android App and detect the ibeacon's major/minor numbers. When I call beaconManager.startMonitoring(new Region("myMonitoringUniqueId", null, null, null)); the App runs well. And I make the program I design to the classes.jar file.

Now I use Unity and try to use this jar file to detect the ibeacon on my Unity Android Application. I put the classes.jar and AndroidManifest.xml in to my Unity project and try to call the beaconManager.startMonitoring(new Region("myMonitoringUniqueId", null, null, null)); the compile and Build are passed, but when I install the apk on my phone and run it, the application crash.

The Phone I use: Zenfone 7 -- Android 11
The version of Unity: Unity2019.4.31f1

The error log:

java.lang.NoSuchMethodError: No virtual method startRangingBeacons(Lorg/altbeacon/beacon/Region;)V in class Lorg/altbeacon/beacon/BeaconManager; or its super classes (declaration of 'org.altbeacon.beacon.BeaconManager' appears in /data/app/~~lOm13WWD8uZ_nbS2pIVb3A==/com.example.aartesting-LqhAFNQZtBYPkoICvZt1ig==/base.apk)

It's sorry that my English is not very well, and I afraid that I can't describe my problem clearly. If you want to know more about my problem, please let me know, I will try to make you know more about the situation I met.

Thank you!

Viktor Jovanovski
  • 1,513
  • 10
  • 26
  • What version of the AndroidBeaconLibrary are you using with Unity2019.4.31f1? While you mention version 2.17.1, note that the startRangingBeacons method was added in library version 2.19. Earlier library versions do not have that method and instead have a similar startRangingBeaconsInRegion method. It may be that you compiled with version 2.19 of the library and are running with the 2.17 version missing the method. – davidgyoung Oct 20 '21 at 13:16
  • @davidgyoung Thank for your comment! I also use version 2.17.1 in my Unity project. And I have try to use `android-beacon-library-2.17.1.aar` library to make a Android Studio Application, I called `beaconManager.startRangingBeacons(new Region("myRangingUniqueId", null, null, null));` and the Application worked well. So I think that it is not the version problem. I'm still looking for the solution to this problem. – hanlaji9514 Oct 21 '21 at 15:02
  • Please trust me -- I am the lead developer on the Android Beacon Library. Library version 2.17.1 **does not** have a method called `startRangingBeacons`. You can look for yourself in the git repository for that version tag [here](https://github.com/AltBeacon/android-beacon-library/blob/2.17.1/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L833). In version 2.17.1 the equivalent method is named `startRangingBeaconsInRegion`. The method name you mention exists only in library version 2.19 and higher. – davidgyoung Oct 22 '21 at 01:43
  • I see it. because I use `implementation 'org.altbeacon:android-beacon-library:2+'` in my Build.Gradle, so it auto implement the latest version in my project. I change it to 2.17.1 version. And I want to know how to call remoteExcepection from `startRangingBeaconsInRegion`?, It seems that it is not equal as the example on [link](https://altbeacon.github.io/android-beacon-library/samples-java.html). Thank you very much! – hanlaji9514 Oct 22 '21 at 04:52
  • `startRangingBeaconsInRegion` is deprecated because it is much more complex to use than the replacement `startRangingBeacons` in 2.19+. The deprecated method should not be used for new apps. Please consider this an "experts only" method going forward, and avoid it unless you really know what you are doing. – davidgyoung Oct 22 '21 at 14:36

1 Answers1

0

I suspect the problem is caused by R8 or ProGuard settings, which obfuscate code to prevent reverse engineering. Aggressive R8 or ProGuard settings will rename certain classes and methods (including library class methods like startRangingBeacons mentioned in the stack trace).

You can read more about how R8 and ProGuard work here: https://developer.android.com/studio/build/shrink-code

To confirm this is the problem, you should edit your project settings for Android to disable R8 and ProGuard. Doing so for a native Android project is as simple as editing the build.gradle file and setting minifyEnabled false. Since I am not a Unity expert, I cannot tell you how to do the same thing from Unity.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • I try to disable minify in Unity, and I found that the default setting is already disabled. My problem is still unsolved. Thank you! – hanlaji9514 Oct 20 '21 at 00:45