From 1439e6392ae75a05f48ccec965b894f256377cc5 Mon Sep 17 00:00:00 2001 From: mar-v-in Date: Sat, 3 Jan 2015 15:25:12 +0100 Subject: [PATCH] Build UnifiedNlp as library if project is named UnifiedNlpLib --- build.gradle | 48 ++++++++++++------- .../microg/nlp/location/BackendHelper.java | 1 - 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index fa1673b..63ec537 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import java.util.concurrent.atomic.AtomicBoolean + buildscript { repositories { mavenCentral() @@ -7,7 +9,13 @@ buildscript { } } -apply plugin: 'com.android.application' +final boolean buildNlpAsLib = name.equals('UnifiedNlpLib') + +if (buildNlpAsLib) { + apply plugin: 'com.android.library' +} else { + apply plugin: 'com.android.application' +} dependencies { compile 'com.android.support:support-v4:21.0.2' @@ -22,13 +30,16 @@ dependencies { tasks.getByName('preBuild').dependsOn += 'compatSetup' -task compatSetup(dependsOn: [project('compat').path+':assembleDebug', project('compat').path+':assembleRelease']) << { - final java.util.concurrent.atomic.AtomicBoolean classpathSet = new java.util.concurrent.atomic.AtomicBoolean(false); +task compatSetup(dependsOn: [project('compat').path + ':assembleDebug', project('compat').path + ':assembleRelease']) << { + final AtomicBoolean classpathSet = new AtomicBoolean(false); tasks.findAll { it.name.startsWith('compile') && it.name.endsWith('Java') }.each { it.doFirst { if (!classpathSet.get()) { - android.applicationVariants.all { - variant -> variant.javaCompile.classpath += project('compat').files('build/intermediates/bundles/' + (variant.name.endsWith('ebug') ? 'debug' : 'release') + '/classes.jar'); + def variants; + if (buildNlpAsLib) variants = android.libraryVariants; + else variants = android.applicationVariants; + variants.all { + it.javaCompile.classpath += project('compat').files('build/intermediates/bundles/' + (it.name.endsWith('ebug') ? 'debug' : 'release') + '/classes.jar'); }; classpathSet.set(true); } @@ -36,7 +47,6 @@ task compatSetup(dependsOn: [project('compat').path+':assembleDebug', project('c }; } - android { compileSdkVersion 21 buildToolsVersion "21.0.2" @@ -44,22 +54,28 @@ android { sourceSets { main { - manifest.srcFile 'AndroidManifest.xml' + if (buildNlpAsLib) { + manifest.srcFile 'EmptyAndroidManifest.xml' + } else { + manifest.srcFile 'AndroidManifest.xml' + } java.srcDirs = ['src', 'api/src'] aidl.srcDirs = ['src', 'api/src'] res.srcDirs = ['res'] } } - productFlavors { - NetworkLocation { - applicationId = 'com.google.android.gms' - } - LegacyNetworkLocation { - applicationId = 'com.google.android.location' - } - UnifiedNlp { - applicationId = 'org.microg.nlp' + if (!buildNlpAsLib) { + productFlavors { + NetworkLocation { + applicationId = 'com.google.android.gms' + } + LegacyNetworkLocation { + applicationId = 'com.google.android.location' + } + UnifiedNlp { + applicationId = 'org.microg.nlp' + } } } } diff --git a/src/org/microg/nlp/location/BackendHelper.java b/src/org/microg/nlp/location/BackendHelper.java index 287129b..497e576 100644 --- a/src/org/microg/nlp/location/BackendHelper.java +++ b/src/org/microg/nlp/location/BackendHelper.java @@ -1,6 +1,5 @@ package org.microg.nlp.location; -import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.ComponentName; import android.content.Context;