K K
K K

Reputation: 986

How to add service in a library in android?

I have a project with service which scans the Bluetooth devices in the range and when i get the signal it will broadcast the device details.

I want to create a library of that service so anyone can import my library and use it.

How can i do this ?

Upvotes: 1

Views: 179

Answers (2)

K K
K K

Reputation: 986

I got the solution

First make changes in the build.gradle do the changes as show bellow

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 22
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:22.2.1'
}

task deleteOldJar(type: Delete){
    delete 'release/customlib.jar'
}

task exportJar(type: Copy) {
    from('/build/intermediates/bundles/release/')
    into('/release/')
    include('classes.jar')
    //rename the file name as u want
    rename('classes.jar','myLibrary.jar')
}

exportJar.dependsOn(deleteOldJar,build)

sync the project then click on the right menu bar gradle option u will

-MyLibrary

-:app/Task/Other/exportJar

here you will see exportJar double click on it will create a jar file after the build successful u can check the jar file at location /app/release/MyLibrary.jar

Upvotes: 2

Bilal Qamar
Bilal Qamar

Reputation: 342

Your question is not very clear. For building a library, you must have source code for it. Once you have the library, a system service would attach that library with itself either at boot time or event-based. You need to be clear what you need to do. You can not add a service in a library rather it's the opposite.

Upvotes: 0

Related Questions