Search code examples
androidgradletitanium

Add local .aar files to Titanium SDK 9 Android module


I'm creating an Android module using Titanium SDK 9. I have 2 .aar files that I need to include in my module. According to the documentation you cannot add them to the lib directory anymore:

"With Titanium 6.1.1 - 8.3.1, you can also copy AAR (Android Archive) library files to the module's lib directory. However, this is not supported as of Titanium 9.0.0, which requires you to reference these AAR libraries via a build.gradle file instead."

But how do I reference them correctly? The below configuration of my build.gradle file compiles, but when I use the module, I see and error like 'Failed resolution of: Lpolar/com/sdk/api/PolarBleApiDefaultImpl' immediately when I use some of the .aar files classes:

implementation files('../../libs/polar-ble-sdk.aar')
implementation files('../../libs/polar-protobuf-release.aar')
// Below 2 lines also compile
// compile files('../../libs/polar-ble-sdk.aar')
// compile files('../../libs/polar-protobuf-release.aar')
implementation group: 'commons-io', name: 'commons-io', version: '2.4'
implementation 'com.google.protobuf:protobuf-java:3.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

The call I'm trying to do in my Titanium project and causes the error:

import polar.com.sdk.api.PolarBleApi;
import polar.com.sdk.api.PolarBleApiDefaultImpl;

// and then later on

PolarBleApi api = PolarBleApiDefaultImpl.defaultImplementation(this, 
PolarBleApi.FEATURE_HR);

Solution

  • Found the libraries at https://github.com/polarofficial/polar-ble-sdk

    Using this build.gradle

    repositories {
           maven { url "https://oss.jfrog.org/libs-snapshot" }
       }
    
    
    dependencies {
        implementation files('../../libs/polar-ble-sdk.aar')
        implementation files('../../libs/polar-protobuf-release.aar')
        implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
        implementation 'io.reactivex.rxjava3:rxjava:3.0.0'
    }
    
    

    works fine. No problems using import polar.com.sdk.api.PolarBleApi; or auto-completion with Android Studio. Compiling works fine (but I didn't try the module in Titanium at the end).

    edit:

    • add the build.gradle to your app, too: platform/android/build.gradle (same content)
    • app: create /build/libs and add the libs
    • module:
        @Kroll.method
        public void create()
        {
            PolarBleApi api = PolarBleApiDefaultImpl.defaultImplementation(TiApplication.getAppCurrentActivity(), PolarBleApi.FEATURE_HR);
            Log.i("Polar", "Version: " + PolarBleApiDefaultImpl.versionInfo());
        }
    
    • app:
    var window = Ti.UI.createWindow({
        title: "Test"
    });
    var polar = require("ti.polar");
    
    polar.create();
    
    window.open();
    

    output: [INFO] Polar: (main) [92,92] Version: 2.2.2