xbao / runnerup

A open source run tracker
GNU General Public License v3.0
0 stars 0 forks source link

hrdevice broken release build: samsung, IBluetoothProvider, proguard #1

Closed xbao closed 9 years ago

xbao commented 9 years ago

The Samsung BLE library (used for 4.1, 4.2 and 4.2.2) uses the following hidden classes:

android.bluetooth.IBluetoothManager
android.bluetooth.IBluetoothStateChangeCallback
android.os.ServiceManager

as well as some hidden methods in android.bluetooth.BluetoothDevice. This causes errors in proguard when it tries to identify dead code

proguard warning:

:app:proguardLatestRelease
Warning: com.samsung.android.sdk.bt.gatt.a: can't find superclass or interface android.bluetooth.IBluetoothStateChangeCallback$Stub
Warning: com.samsung.android.sdk.bt.gatt.d: can't find superclass or interface android.bluetooth.IBluetoothStateChangeCallback$Stub
Warning: com.samsung.android.sdk.bt.gatt.BluetoothGatt: can't find referenced class android.bluetooth.IBluetoothManager
Warning: com.samsung.android.sdk.bt.gatt.BluetoothGatt: can't find referenced class android.bluetooth.IBluetoothManager$Stub
Warning: com.samsung.android.sdk.bt.gatt.BluetoothGatt: can't find referenced class android.os.ServiceManager
...lots of more...
Warning: there were 22 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 4 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
xbao commented 9 years ago

It looks like the samsung BT SDK is accessing classes that aren't exported by the Android framework.

Example: android.os.ServiceManager (notice the /** @hide **/)

These are not in the jar files released in the SDK.

Given this, the next question is why it compiles without warning normally

xbao commented 9 years ago

Looking at the jar files in the Android SDK, it seems only layoutlib.jar exports them

=== file: /home/xiao/dev/android-sdk/android-sdk-linux/platforms/android-17/data/layoutlib.jar ===
android/os/ServiceManagerProxy.class
android/os/ServiceManagerNative.class
android/os/ServiceManager.class
--
=== file: /home/xiao/dev/android-sdk/android-sdk-linux/platforms/android-20/data/layoutlib.jar ===
android/os/ServiceManagerProxy.class
android/os/ServiceManagerNative.class
android/os/ServiceManager.class
--
=== file: /home/xiao/dev/android-sdk/android-sdk-linux/platforms/android-21/data/layoutlib.jar ===
android/os/ServiceManager.class
android/os/ServiceManagerNative.class
android/os/ServiceManagerProxy.class
xbao commented 9 years ago

To ignore the warnings, as recommended on the samsung developer forum (thread), we can add -dontwarn com.samsung.** to the proguard rules.

I'm still not sure why it happens only for the hr code as a module. It could be because it's a library and so proguard doesn't include layoutlib.jar. I compared the output of

gradle clean && gradle :app:assembleFroyoRelease --debug 2>&1 > froyo.debug.txt

between the working build without hrmodule and the broken build with it. There were a couple of jar files mentioned in the working build that weren't mentioned in the broken one, but none of them had the classes the Samsung library needed.

Not going to dig further as I doubt ignoring the warnings will break anything. Those classes are definitely available at runtime for the few Android versions in which the Samsung BLE library is used.