Build UnifiedNlp as library if project is named UnifiedNlpLib

This commit is contained in:
mar-v-in 2015-01-03 15:25:12 +01:00
parent 854fdc1572
commit 1439e6392a
2 changed files with 32 additions and 17 deletions

View file

@ -1,3 +1,5 @@
import java.util.concurrent.atomic.AtomicBoolean
buildscript { buildscript {
repositories { repositories {
mavenCentral() 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 { dependencies {
compile 'com.android.support:support-v4:21.0.2' compile 'com.android.support:support-v4:21.0.2'
@ -22,13 +30,16 @@ dependencies {
tasks.getByName('preBuild').dependsOn += 'compatSetup' tasks.getByName('preBuild').dependsOn += 'compatSetup'
task compatSetup(dependsOn: [project('compat').path+':assembleDebug', project('compat').path+':assembleRelease']) << { 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); final AtomicBoolean classpathSet = new AtomicBoolean(false);
tasks.findAll { it.name.startsWith('compile') && it.name.endsWith('Java') }.each { tasks.findAll { it.name.startsWith('compile') && it.name.endsWith('Java') }.each {
it.doFirst { it.doFirst {
if (!classpathSet.get()) { if (!classpathSet.get()) {
android.applicationVariants.all { def variants;
variant -> variant.javaCompile.classpath += project('compat').files('build/intermediates/bundles/' + (variant.name.endsWith('ebug') ? 'debug' : 'release') + '/classes.jar'); 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); classpathSet.set(true);
} }
@ -36,7 +47,6 @@ task compatSetup(dependsOn: [project('compat').path+':assembleDebug', project('c
}; };
} }
android { android {
compileSdkVersion 21 compileSdkVersion 21
buildToolsVersion "21.0.2" buildToolsVersion "21.0.2"
@ -44,22 +54,28 @@ android {
sourceSets { sourceSets {
main { main {
manifest.srcFile 'AndroidManifest.xml' if (buildNlpAsLib) {
manifest.srcFile 'EmptyAndroidManifest.xml'
} else {
manifest.srcFile 'AndroidManifest.xml'
}
java.srcDirs = ['src', 'api/src'] java.srcDirs = ['src', 'api/src']
aidl.srcDirs = ['src', 'api/src'] aidl.srcDirs = ['src', 'api/src']
res.srcDirs = ['res'] res.srcDirs = ['res']
} }
} }
productFlavors { if (!buildNlpAsLib) {
NetworkLocation { productFlavors {
applicationId = 'com.google.android.gms' NetworkLocation {
} applicationId = 'com.google.android.gms'
LegacyNetworkLocation { }
applicationId = 'com.google.android.location' LegacyNetworkLocation {
} applicationId = 'com.google.android.location'
UnifiedNlp { }
applicationId = 'org.microg.nlp' UnifiedNlp {
applicationId = 'org.microg.nlp'
}
} }
} }
} }

View file

@ -1,6 +1,5 @@
package org.microg.nlp.location; package org.microg.nlp.location;
import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;